Skip to content

Commit

Permalink
Fix #3620 - Fix frequently used emojis, stop relying on Apple's keybo…
Browse files Browse the repository at this point in the history
…ard values and store everything app side instead.
  • Loading branch information
stefanceriu committed Dec 16, 2024
1 parent f9be39e commit e04c874
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
6 changes: 5 additions & 1 deletion ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class AppSettings {
case hasRunNotificationPermissionsOnboarding
case hasRunIdentityConfirmationOnboarding

case frequentlyUsedSystemEmojis

case enableNotifications
case enableInAppNotifications
case pusherProfileTag
Expand All @@ -40,7 +42,6 @@ final class AppSettings {
case hideTimelineMedia

case elementCallBaseURLOverride
case elementCallEncryptionEnabled

// Feature flags
case slidingSyncDiscovery
Expand Down Expand Up @@ -231,6 +232,9 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.hasRunIdentityConfirmationOnboarding, defaultValue: false, storageType: .userDefaults(store))
var hasRunIdentityConfirmationOnboarding

@UserPreference(key: UserDefaultsKeys.frequentlyUsedSystemEmojis, defaultValue: [String](), storageType: .userDefaults(store))
var frequentlyUsedSystemEmojis

// MARK: - Home Screen

@UserPreference(key: UserDefaultsKeys.hideUnreadMessagesBadge, defaultValue: false, storageType: .userDefaults(store))
Expand Down
19 changes: 3 additions & 16 deletions ElementX/Sources/Services/Emojis/EmojiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,18 @@ class EmojiProvider: EmojiProviderProtocol {
return []
}

guard let preferences = UserDefaults(suiteName: "com.apple.EmojiPreferences"),
let defaults = preferences.dictionary(forKey: "EMFDefaultsKey"),
let recents = defaults["EMFRecentsKey"] as? [String]
else {
return []
}

return recents
return appSettings.frequentlyUsedSystemEmojis
}

func markEmojiAsFrequentlyUsed(_ emoji: String) {
guard !ProcessInfo.processInfo.isiOSAppOnMac else {
return
}

guard let preferences = UserDefaults(suiteName: "com.apple.EmojiPreferences"),
let defaults = preferences.dictionary(forKey: "EMFDefaultsKey"),
let recents = defaults["EMFRecentsKey"] as? [String] else {
return
}

var uniqueOrderedRecents = OrderedSet(recents)
var uniqueOrderedRecents = OrderedSet(appSettings.frequentlyUsedSystemEmojis)
uniqueOrderedRecents.insert(emoji, at: 0)

preferences.setValue(["EMFRecentsKey": Array(uniqueOrderedRecents)], forKey: "EMFDefaultsKey")
appSettings.frequentlyUsedSystemEmojis = Array(uniqueOrderedRecents)
}

// MARK: - Private
Expand Down

0 comments on commit e04c874

Please sign in to comment.