Fix crash when a server has an emoji category named after its domain (#1045)
This commit is contained in:
parent
774b7830d5
commit
88d54b6151
|
@ -8,5 +8,6 @@
|
|||
import Foundation
|
||||
|
||||
public enum CustomEmojiPickerSection: Equatable, Hashable {
|
||||
case uncategorized
|
||||
case emoji(name: String)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import MastodonCore
|
|||
extension CustomEmojiPickerSection {
|
||||
static func collectionViewDiffableDataSource(
|
||||
collectionView: UICollectionView,
|
||||
authContext: AuthContext,
|
||||
context: AppContext
|
||||
) -> UICollectionViewDiffableDataSource<CustomEmojiPickerSection, CustomEmojiPickerItem> {
|
||||
let dataSource = UICollectionViewDiffableDataSource<CustomEmojiPickerSection, CustomEmojiPickerItem>(collectionView: collectionView) { [weak context] collectionView, indexPath, item -> UICollectionViewCell? in
|
||||
|
@ -44,6 +45,8 @@ extension CustomEmojiPickerSection {
|
|||
case String(describing: CustomEmojiPickerHeaderCollectionReusableView.self):
|
||||
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: CustomEmojiPickerHeaderCollectionReusableView.self), for: indexPath) as! CustomEmojiPickerHeaderCollectionReusableView
|
||||
switch section {
|
||||
case .uncategorized:
|
||||
header.titleLabel.text = authContext.mastodonAuthenticationBox.domain.uppercased()
|
||||
case .emoji(let name):
|
||||
header.titleLabel.text = name
|
||||
}
|
||||
|
|
|
@ -102,11 +102,11 @@ extension ComposeContentViewModel {
|
|||
) {
|
||||
let diffableDataSource = CustomEmojiPickerSection.collectionViewDiffableDataSource(
|
||||
collectionView: collectionView,
|
||||
authContext: authContext,
|
||||
context: context
|
||||
)
|
||||
self.customEmojiPickerDiffableDataSource = diffableDataSource
|
||||
|
||||
let domain = authContext.mastodonAuthenticationBox.domain.uppercased()
|
||||
customEmojiViewModel?.emojis
|
||||
// Don't block the main queue
|
||||
.receive(on: DispatchQueue.global(qos: .userInteractive))
|
||||
|
@ -144,11 +144,13 @@ extension ComposeContentViewModel {
|
|||
.map({ (emojiMap) -> NSDiffableDataSourceSnapshot<CustomEmojiPickerSection, CustomEmojiPickerItem> in
|
||||
|
||||
var snapshot = NSDiffableDataSourceSnapshot<CustomEmojiPickerSection, CustomEmojiPickerItem>()
|
||||
let customEmojiSection = CustomEmojiPickerSection.emoji(name: domain)
|
||||
snapshot.appendSections([customEmojiSection])
|
||||
snapshot.appendItems(emojiMap.noCategory.map({ emoji in
|
||||
CustomEmojiPickerItem.emoji(attribute: CustomEmojiPickerItem.CustomEmojiAttribute(emoji: emoji))
|
||||
}), toSection: customEmojiSection)
|
||||
if !emojiMap.noCategory.isEmpty {
|
||||
let customEmojiSection = CustomEmojiPickerSection.uncategorized
|
||||
snapshot.appendSections([customEmojiSection])
|
||||
snapshot.appendItems(emojiMap.noCategory.map({ emoji in
|
||||
CustomEmojiPickerItem.emoji(attribute: CustomEmojiPickerItem.CustomEmojiAttribute(emoji: emoji))
|
||||
}), toSection: customEmojiSection)
|
||||
}
|
||||
emojiMap.categorised.keys.sorted().forEach { category in
|
||||
let section = CustomEmojiPickerSection.emoji(name: category)
|
||||
snapshot.appendSections([section])
|
||||
|
|
Loading…
Reference in New Issue