Fix crash when there are duplicate emojis

Closes #164
This commit is contained in:
Shadowfacts 2022-09-15 21:10:52 -04:00
parent 80c4fcce82
commit 0f71d61b88
1 changed files with 7 additions and 1 deletions

View File

@ -256,13 +256,19 @@ struct ComposeAutocompleteEmojisView: View {
} }
mastodonController.getCustomEmojis { (emojis) in mastodonController.getCustomEmojis { (emojis) in
self.emojis = let emojis: [Emoji] =
emojis.map { (emoji) -> (Emoji, (matched: Bool, score: Int)) in emojis.map { (emoji) -> (Emoji, (matched: Bool, score: Int)) in
(emoji, FuzzyMatcher.match(pattern: query, str: emoji.shortcode)) (emoji, FuzzyMatcher.match(pattern: query, str: emoji.shortcode))
} }
.filter(\.1.matched) .filter(\.1.matched)
.sorted { $0.1.score > $1.1.score } .sorted { $0.1.score > $1.1.score }
.map(\.0) .map(\.0)
var shortcodes = Set<String>()
self.emojis = []
for emoji in emojis where !shortcodes.contains(emoji.shortcode) {
self.emojis.append(emoji)
shortcodes.insert(emoji.shortcode)
}
} }
} }
} }