mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Improve sticker and emoji search
This commit is contained in:
parent
b26a539c11
commit
094341b520
@ -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))
|
||||
|
@ -69,21 +69,16 @@ public final class EmojiSuggestionsComponent: Component {
|
||||
|
||||
var existingIds = Set<EngineMedia.Id>()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user