Skip to content

Commit

Permalink
Fix the order of the frequently used emojis when showing them in the …
Browse files Browse the repository at this point in the history
…full reaction picker.
  • Loading branch information
stefanceriu committed Oct 26, 2024
1 parent 7a47e37 commit ad5b22e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ElementX/Sources/Services/Emojis/EmojiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import OrderedCollections

class EmojiProvider: EmojiProviderProtocol {
private let maxFrequentEmojis = 20
private let loader: EmojiLoaderProtocol
private let appSettings: AppSettings

Expand All @@ -31,9 +32,18 @@ class EmojiProvider: EmojiProviderProtocol {
partialResult + category.emojis
}

// Map frequently used system unicode emojis to our emoji provider ones
let frequentlyUsedEmojis = frequentlyUsedSystemEmojis().prefix(20)
let emojis = allEmojis.filter { frequentlyUsedEmojis.contains($0.unicode) }
// Map frequently used system unicode emojis to our emoji provider ones and preserve the order
let frequentlyUsedEmojis = frequentlyUsedSystemEmojis().prefix(maxFrequentEmojis)
let emojis = allEmojis
.filter { frequentlyUsedEmojis.contains($0.unicode) }
.sorted { first, second in
guard let firstIndex = frequentlyUsedEmojis.firstIndex(of: first.unicode),
let secondIndex = frequentlyUsedEmojis.firstIndex(of: second.unicode) else {
return false
}

return firstIndex < secondIndex
}

if !emojis.isEmpty {
emojiCategories.insert(.init(id: EmojiCategory.frequentlyUsedCategoryIdentifier, emojis: emojis), at: 0)
Expand Down

0 comments on commit ad5b22e

Please sign in to comment.