From 0f71d61b88686c82e8c4c35f30c3c80fbe80c84d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 15 Sep 2022 21:10:52 -0400 Subject: [PATCH] Fix crash when there are duplicate emojis Closes #164 --- Tusker/Screens/Compose/ComposeAutocompleteView.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Compose/ComposeAutocompleteView.swift b/Tusker/Screens/Compose/ComposeAutocompleteView.swift index fca50d0a19..a82fe27d14 100644 --- a/Tusker/Screens/Compose/ComposeAutocompleteView.swift +++ b/Tusker/Screens/Compose/ComposeAutocompleteView.swift @@ -256,13 +256,19 @@ struct ComposeAutocompleteEmojisView: View { } mastodonController.getCustomEmojis { (emojis) in - self.emojis = + let emojis: [Emoji] = emojis.map { (emoji) -> (Emoji, (matched: Bool, score: Int)) in (emoji, FuzzyMatcher.match(pattern: query, str: emoji.shortcode)) } .filter(\.1.matched) .sorted { $0.1.score > $1.1.score } .map(\.0) + var shortcodes = Set() + self.emojis = [] + for emoji in emojis where !shortcodes.contains(emoji.shortcode) { + self.emojis.append(emoji) + shortcodes.insert(emoji.shortcode) + } } } }