diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift index 70159a16c5..b9198a4b06 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift @@ -160,14 +160,7 @@ func _internal_searchStickers(account: Account, query: [String], scope: SearchSt if !currentItems.contains(item.file.fileId) { currentItems.insert(item.file.fileId) - var stringRepresentations: [String] = [] - for key in item.indexKeys { - key.withDataNoCopy { data in - if let string = String(data: data, encoding: .utf8) { - stringRepresentations.append(string) - } - } - } + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() if !recentItemsIds.contains(item.file.fileId) { if item.file.isPremiumSticker { installedPremiumItems.append(FoundStickerItem(file: item.file, stringRepresentations: stringRepresentations)) @@ -178,6 +171,11 @@ func _internal_searchStickers(account: Account, query: [String], scope: SearchSt } } else { matchingRecentItemsIds.insert(item.file.fileId) + if item.file.isAnimatedSticker || item.file.isVideoSticker { + recentAnimatedItems.append(item.file) + } else { + recentItems.append(item.file) + } } } } @@ -202,6 +200,7 @@ func _internal_searchStickers(account: Account, query: [String], scope: SearchSt } } + result.append(contentsOf: installedPremiumItems) result.append(contentsOf: installedAnimatedItems) result.append(contentsOf: installedItems) } @@ -413,14 +412,7 @@ func _internal_searchEmoji(account: Account, query: [String], scope: SearchStick if !currentItems.contains(file.fileId) { currentItems.insert(file.fileId) - var stringRepresentations: [String] = [] - for key in item.indexKeys { - key.withDataNoCopy { data in - if let string = String(data: data, encoding: .utf8) { - stringRepresentations.append(string) - } - } - } + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() for stringRepresentation in stringRepresentations { if querySet.contains(stringRepresentation) { installedItems.append(FoundStickerItem(file: file, stringRepresentations: stringRepresentations)) diff --git a/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift b/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift index 143d96eff1..348ce54803 100644 --- a/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift +++ b/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift @@ -69,21 +69,16 @@ public final class EmojiSuggestionsComponent: Component { var existingIds = Set() for entry in view.entries { - guard let item = entry.item as? StickerPackItem else { + guard let item = entry.item as? StickerPackItem, !item.file.isPremiumEmoji || hasPremium else { continue } - for attribute in item.file.attributes { - switch attribute { - case let .CustomEmoji(_, _, alt, _): - if alt == query || (!normalizedQuery.isEmpty && alt == normalizedQuery) { - if !item.file.isPremiumEmoji || hasPremium { - if !existingIds.contains(item.file.fileId) { - existingIds.insert(item.file.fileId) - result.append(item.file) - } - } + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() + for stringRepresentation in stringRepresentations { + if stringRepresentation == query || (!normalizedQuery.isEmpty && stringRepresentation == normalizedQuery) { + if !existingIds.contains(item.file.fileId) { + existingIds.insert(item.file.fileId) + result.append(item.file) } - default: break } } diff --git a/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/InputContextQueries.swift b/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/InputContextQueries.swift index 0546d1cf9e..3051274d1a 100644 --- a/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/InputContextQueries.swift +++ b/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/InputContextQueries.swift @@ -257,18 +257,13 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, cha var result: [(String, TelegramMediaFile?, String)] = [] for entry in view.entries { - guard let item = entry.item as? StickerPackItem else { + guard let item = entry.item as? StickerPackItem, !item.file.isPremiumEmoji || hasPremium else { continue } - for attribute in item.file.attributes { - switch attribute { - case let .CustomEmoji(_, _, alt, _): - if alt == query { - if !item.file.isPremiumEmoji || hasPremium { - result.append((alt, item.file, alt)) - } - } - default: + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() + for stringRepresentation in stringRepresentations { + if stringRepresentation == query { + result.append((stringRepresentation, item.file, stringRepresentation)) break } } @@ -312,18 +307,13 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, cha } for entry in view.entries { - guard let item = entry.item as? StickerPackItem else { + guard let item = entry.item as? StickerPackItem, !item.file.isPremiumEmoji || hasPremium else { continue } - for attribute in item.file.attributes { - switch attribute { - case let .CustomEmoji(_, _, alt, _): - if !alt.isEmpty, let keyword = allEmoticons[alt] { - if !item.file.isPremiumEmoji || hasPremium { - result.append((alt, item.file, keyword)) - } - } - default: + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() + for stringRepresentation in stringRepresentations { + if let keyword = allEmoticons[stringRepresentation] { + result.append((stringRepresentation, item.file, keyword)) break } } diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift index 2572058c67..f765fa6430 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift @@ -382,18 +382,13 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee var result: [(String, TelegramMediaFile?, String)] = [] for entry in view.entries { - guard let item = entry.item as? StickerPackItem else { + guard let item = entry.item as? StickerPackItem, !item.file.isPremiumEmoji || hasPremium else { continue } - for attribute in item.file.attributes { - switch attribute { - case let .CustomEmoji(_, _, alt, _): - if alt == query { - if !item.file.isPremiumEmoji || hasPremium { - result.append((alt, item.file, alt)) - } - } - default: + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() + for stringRepresentation in stringRepresentations { + if stringRepresentation == query { + result.append((stringRepresentation, item.file, stringRepresentation)) break } } @@ -437,18 +432,13 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee } for entry in view.entries { - guard let item = entry.item as? StickerPackItem else { + guard let item = entry.item as? StickerPackItem, !item.file.isPremiumEmoji || hasPremium else { continue } - for attribute in item.file.attributes { - switch attribute { - case let .CustomEmoji(_, _, alt, _): - if !alt.isEmpty, let keyword = allEmoticons[alt] { - if !item.file.isPremiumEmoji || hasPremium { - result.append((alt, item.file, keyword)) - } - } - default: + let stringRepresentations = item.getStringRepresentationsOfIndexKeys() + for stringRepresentation in stringRepresentations { + if let keyword = allEmoticons[stringRepresentation] { + result.append((stringRepresentation, item.file, keyword)) break } }