fix: remove default emojis from recently used

pull/638/head
Ryan Zhao 3 years ago
parent c91bdb3aeb
commit 4c011f14e8

@ -61,7 +61,7 @@ final class ContextMenuVC : UIViewController {
self.dismiss = dismiss self.dismiss = dismiss
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
Storage.read { transaction in Storage.read { transaction in
self.recentEmoji = Array(Storage.shared.getRecentEmoji(transaction: transaction)[...5]) self.recentEmoji = Array(Storage.shared.getRecentEmoji(withDefaultEmoji: true, transaction: transaction)[...5])
} }
} }

@ -67,7 +67,7 @@ class EmojiPickerCollectionView: UICollectionView {
tapGestureRecognizer.delegate = self tapGestureRecognizer.delegate = self
Storage.read { transaction in Storage.read { transaction in
self.recentEmoji = Storage.shared.getRecentEmoji(transaction: transaction) self.recentEmoji = Storage.shared.getRecentEmoji(withDefaultEmoji: false, transaction: transaction)
// Some emoji have two different code points but identical appearances. Let's remove them! // Some emoji have two different code points but identical appearances. Let's remove them!
// If we normalize to a different emoji than the one currently in our array, we want to drop // If we normalize to a different emoji than the one currently in our array, we want to drop

@ -3,11 +3,11 @@ extension Storage {
private static let emojiPickerCollection = "EmojiPickerCollection" private static let emojiPickerCollection = "EmojiPickerCollection"
private static let recentEmojiKey = "recentEmoji" private static let recentEmojiKey = "recentEmoji"
func getRecentEmoji(transaction: YapDatabaseReadTransaction) -> [EmojiWithSkinTones] { func getRecentEmoji(withDefaultEmoji: Bool, transaction: YapDatabaseReadTransaction) -> [EmojiWithSkinTones] {
var rawRecentEmoji = transaction.object(forKey: Self.recentEmojiKey, inCollection: Self.emojiPickerCollection) as? [String] ?? [] var rawRecentEmoji = transaction.object(forKey: Self.recentEmojiKey, inCollection: Self.emojiPickerCollection) as? [String] ?? []
let defaultEmoji = ["🙈", "🙉", "🙊", "😈", "🥸", "🐀"].filter{ !rawRecentEmoji.contains($0) } let defaultEmoji = ["🙈", "🙉", "🙊", "😈", "🥸", "🐀"].filter{ !rawRecentEmoji.contains($0) }
if rawRecentEmoji.count < 6 { if rawRecentEmoji.count < 6 && withDefaultEmoji {
rawRecentEmoji.append(contentsOf: defaultEmoji[..<(defaultEmoji.count - rawRecentEmoji.count)]) rawRecentEmoji.append(contentsOf: defaultEmoji[..<(defaultEmoji.count - rawRecentEmoji.count)])
} }
@ -15,7 +15,7 @@ extension Storage {
} }
func recordRecentEmoji(_ emoji: EmojiWithSkinTones, transaction: YapDatabaseReadWriteTransaction) { func recordRecentEmoji(_ emoji: EmojiWithSkinTones, transaction: YapDatabaseReadWriteTransaction) {
let recentEmoji = getRecentEmoji(transaction: transaction) let recentEmoji = getRecentEmoji(withDefaultEmoji: false, transaction: transaction)
guard recentEmoji.first != emoji else { return } guard recentEmoji.first != emoji else { return }
guard emoji.isNormalized else { guard emoji.isNormalized else {
recordRecentEmoji(emoji.normalized, transaction: transaction) recordRecentEmoji(emoji.normalized, transaction: transaction)

Loading…
Cancel
Save