mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Improve stickers search
This commit is contained in:
parent
acac317502
commit
d6b6fafb89
@ -142,12 +142,10 @@ func _internal_searchStickers(account: Account, query: String, scope: SearchStic
|
|||||||
|
|
||||||
var installedItems: [FoundStickerItem] = []
|
var installedItems: [FoundStickerItem] = []
|
||||||
var installedAnimatedItems: [FoundStickerItem] = []
|
var installedAnimatedItems: [FoundStickerItem] = []
|
||||||
|
var installedPremiumItems: [FoundStickerItem] = []
|
||||||
|
|
||||||
for item in transaction.searchItemCollection(namespace: Namespaces.ItemCollection.CloudStickerPacks, query: searchQuery) {
|
for item in transaction.searchItemCollection(namespace: Namespaces.ItemCollection.CloudStickerPacks, query: searchQuery) {
|
||||||
if let item = item as? StickerPackItem {
|
if let item = item as? StickerPackItem {
|
||||||
if item.file.isPremiumSticker && !isPremium {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !currentItems.contains(item.file.fileId) {
|
if !currentItems.contains(item.file.fileId) {
|
||||||
var stringRepresentations: [String] = []
|
var stringRepresentations: [String] = []
|
||||||
for key in item.indexKeys {
|
for key in item.indexKeys {
|
||||||
@ -158,7 +156,9 @@ func _internal_searchStickers(account: Account, query: String, scope: SearchStic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !recentItemsIds.contains(item.file.fileId) {
|
if !recentItemsIds.contains(item.file.fileId) {
|
||||||
if item.file.isAnimatedSticker || item.file.isVideoSticker {
|
if item.file.isPremiumSticker {
|
||||||
|
installedPremiumItems.append(FoundStickerItem(file: item.file, stringRepresentations: stringRepresentations))
|
||||||
|
} else if item.file.isAnimatedSticker || item.file.isVideoSticker {
|
||||||
installedAnimatedItems.append(FoundStickerItem(file: item.file, stringRepresentations: stringRepresentations))
|
installedAnimatedItems.append(FoundStickerItem(file: item.file, stringRepresentations: stringRepresentations))
|
||||||
} else {
|
} else {
|
||||||
installedItems.append(FoundStickerItem(file: item.file, stringRepresentations: stringRepresentations))
|
installedItems.append(FoundStickerItem(file: item.file, stringRepresentations: stringRepresentations))
|
||||||
@ -204,22 +204,34 @@ func _internal_searchStickers(account: Account, query: String, scope: SearchStic
|
|||||||
|
|
||||||
return (result, cached, isPremium, searchStickersConfiguration)
|
return (result, cached, isPremium, searchStickersConfiguration)
|
||||||
} |> mapToSignal { localItems, cached, isPremium, searchStickersConfiguration -> Signal<[FoundStickerItem], NoError> in
|
} |> mapToSignal { localItems, cached, isPremium, searchStickersConfiguration -> Signal<[FoundStickerItem], NoError> in
|
||||||
var tempResult: [FoundStickerItem] = localItems
|
|
||||||
if !scope.contains(.remote) {
|
if !scope.contains(.remote) {
|
||||||
return .single(tempResult)
|
return .single(localItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tempResult: [FoundStickerItem] = []
|
||||||
let currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
let currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
||||||
|
|
||||||
|
var premiumItems: [FoundStickerItem] = []
|
||||||
|
var otherItems: [FoundStickerItem] = []
|
||||||
|
|
||||||
|
for item in localItems {
|
||||||
|
if item.file.isPremiumSticker {
|
||||||
|
premiumItems.append(item)
|
||||||
|
} else {
|
||||||
|
otherItems.append(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let cached = cached {
|
if let cached = cached {
|
||||||
var cachedItems: [FoundStickerItem] = []
|
var cachedItems: [FoundStickerItem] = []
|
||||||
var cachedAnimatedItems: [FoundStickerItem] = []
|
var cachedAnimatedItems: [FoundStickerItem] = []
|
||||||
|
var cachedPremiumItems: [FoundStickerItem] = []
|
||||||
|
|
||||||
for file in cached.items {
|
for file in cached.items {
|
||||||
if file.isPremiumSticker && !isPremium {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !currentItemIds.contains(file.fileId) {
|
if !currentItemIds.contains(file.fileId) {
|
||||||
if file.isAnimatedSticker || file.isVideoSticker {
|
if file.isPremiumSticker {
|
||||||
|
cachedPremiumItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||||
|
} else if file.isAnimatedSticker || file.isVideoSticker {
|
||||||
cachedAnimatedItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
cachedAnimatedItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||||
} else {
|
} else {
|
||||||
cachedItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
cachedItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||||
@ -227,8 +239,42 @@ func _internal_searchStickers(account: Account, query: String, scope: SearchStic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tempResult.append(contentsOf: cachedAnimatedItems)
|
otherItems.append(contentsOf: cachedAnimatedItems)
|
||||||
tempResult.append(contentsOf: cachedItems)
|
otherItems.append(contentsOf: cachedItems)
|
||||||
|
|
||||||
|
let allPremiumItems = premiumItems + cachedPremiumItems
|
||||||
|
let allOtherItems = otherItems + cachedAnimatedItems + cachedItems
|
||||||
|
|
||||||
|
if isPremium {
|
||||||
|
let batchCount = Int(searchStickersConfiguration.normalStickersPerPremiumCount)
|
||||||
|
if batchCount == 0 {
|
||||||
|
tempResult.append(contentsOf: allPremiumItems)
|
||||||
|
tempResult.append(contentsOf: allOtherItems)
|
||||||
|
} else {
|
||||||
|
if allPremiumItems.isEmpty {
|
||||||
|
tempResult.append(contentsOf: allOtherItems)
|
||||||
|
} else {
|
||||||
|
var i = 0
|
||||||
|
for premiumItem in allPremiumItems {
|
||||||
|
if i < allOtherItems.count {
|
||||||
|
for j in i ..< min(i + batchCount, allOtherItems.count) {
|
||||||
|
tempResult.append(allOtherItems[j])
|
||||||
|
}
|
||||||
|
i += batchCount
|
||||||
|
}
|
||||||
|
tempResult.append(premiumItem)
|
||||||
|
}
|
||||||
|
if i < allOtherItems.count {
|
||||||
|
for j in i ..< allOtherItems.count {
|
||||||
|
tempResult.append(allOtherItems[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tempResult.append(contentsOf: allOtherItems)
|
||||||
|
tempResult.append(contentsOf: allPremiumItems.prefix(max(0, Int(searchStickersConfiguration.premiumStickersCount))))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let remote = account.network.request(Api.functions.messages.getStickers(emoticon: query, hash: cached?.hash ?? 0))
|
let remote = account.network.request(Api.functions.messages.getStickers(emoticon: query, hash: cached?.hash ?? 0))
|
||||||
@ -239,44 +285,72 @@ func _internal_searchStickers(account: Account, query: String, scope: SearchStic
|
|||||||
return account.postbox.transaction { transaction -> [FoundStickerItem] in
|
return account.postbox.transaction { transaction -> [FoundStickerItem] in
|
||||||
switch result {
|
switch result {
|
||||||
case let .stickers(hash, stickers):
|
case let .stickers(hash, stickers):
|
||||||
var items: [FoundStickerItem] = []
|
var result: [FoundStickerItem] = []
|
||||||
var animatedItems: [FoundStickerItem] = []
|
let currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
||||||
|
|
||||||
var premiumItems: [FoundStickerItem] = []
|
var premiumItems: [FoundStickerItem] = []
|
||||||
|
var otherItems: [FoundStickerItem] = []
|
||||||
|
|
||||||
var allItems: [FoundStickerItem] = localItems
|
for item in localItems {
|
||||||
let currentItemIds = Set<MediaId>(allItems.map { $0.file.fileId })
|
if item.file.isPremiumSticker {
|
||||||
|
premiumItems.append(item)
|
||||||
|
} else {
|
||||||
|
otherItems.append(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var foundItems: [FoundStickerItem] = []
|
||||||
|
var foundAnimatedItems: [FoundStickerItem] = []
|
||||||
|
var foundPremiumItems: [FoundStickerItem] = []
|
||||||
|
|
||||||
var files: [TelegramMediaFile] = []
|
var files: [TelegramMediaFile] = []
|
||||||
for sticker in stickers {
|
for sticker in stickers {
|
||||||
if let file = telegramMediaFileFromApiDocument(sticker), let id = file.id {
|
if let file = telegramMediaFileFromApiDocument(sticker), let id = file.id {
|
||||||
files.append(file)
|
files.append(file)
|
||||||
if !currentItemIds.contains(id) {
|
if !currentItemIds.contains(id) {
|
||||||
if file.isPremiumSticker {
|
if file.isPremiumSticker {
|
||||||
premiumItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
foundPremiumItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||||
} else if file.isAnimatedSticker || file.isVideoSticker {
|
} else if file.isAnimatedSticker || file.isVideoSticker {
|
||||||
animatedItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
foundAnimatedItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||||
} else {
|
} else {
|
||||||
items.append(FoundStickerItem(file: file, stringRepresentations: []))
|
foundItems.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allItems.append(contentsOf: animatedItems)
|
|
||||||
allItems.append(contentsOf: items)
|
|
||||||
|
|
||||||
var result: [FoundStickerItem] = []
|
let allPremiumItems = premiumItems + foundPremiumItems
|
||||||
|
let allOtherItems = otherItems + foundAnimatedItems + foundItems
|
||||||
|
|
||||||
if isPremium {
|
if isPremium {
|
||||||
if searchStickersConfiguration.normalStickersPerPremiumCount == 0 {
|
let batchCount = Int(searchStickersConfiguration.normalStickersPerPremiumCount)
|
||||||
result.append(contentsOf: premiumItems)
|
if batchCount == 0 {
|
||||||
result.append(contentsOf: allItems)
|
result.append(contentsOf: allPremiumItems)
|
||||||
|
result.append(contentsOf: allOtherItems)
|
||||||
} else {
|
} else {
|
||||||
result.append(contentsOf: premiumItems)
|
if allPremiumItems.isEmpty {
|
||||||
result.append(contentsOf: allItems)
|
result.append(contentsOf: allOtherItems)
|
||||||
|
} else {
|
||||||
|
var i = 0
|
||||||
|
for premiumItem in allPremiumItems {
|
||||||
|
if i < allOtherItems.count {
|
||||||
|
for j in i ..< min(i + batchCount, allOtherItems.count) {
|
||||||
|
result.append(allOtherItems[j])
|
||||||
|
}
|
||||||
|
i += batchCount
|
||||||
|
}
|
||||||
|
result.append(premiumItem)
|
||||||
|
}
|
||||||
|
if i < allOtherItems.count {
|
||||||
|
for j in i ..< allOtherItems.count {
|
||||||
|
result.append(allOtherItems[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.append(contentsOf: allItems)
|
result.append(contentsOf: allOtherItems)
|
||||||
result.append(contentsOf: premiumItems.prefix(max(0, Int(searchStickersConfiguration.premiumStickersCount))))
|
result.append(contentsOf: allPremiumItems.prefix(max(0, Int(searchStickersConfiguration.premiumStickersCount))))
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||||
|
@ -135,7 +135,7 @@ func chatHistoryEntriesForView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if presentationData.largeEmoji, message.media.isEmpty {
|
if presentationData.largeEmoji, message.media.isEmpty {
|
||||||
if stickersEnabled && messageIsElligibleForLargeCustomEmoji(message) {
|
if messageIsElligibleForLargeCustomEmoji(message) {
|
||||||
contentTypeHint = .animatedEmoji
|
contentTypeHint = .animatedEmoji
|
||||||
} else if stickersEnabled && message.text.count == 1, let _ = associatedData.animatedEmojiStickers[message.text.basicEmoji.0], (message.textEntitiesAttribute?.entities.isEmpty ?? true) {
|
} else if stickersEnabled && message.text.count == 1, let _ = associatedData.animatedEmojiStickers[message.text.basicEmoji.0], (message.textEntitiesAttribute?.entities.isEmpty ?? true) {
|
||||||
contentTypeHint = .animatedEmoji
|
contentTypeHint = .animatedEmoji
|
||||||
@ -218,7 +218,7 @@ func chatHistoryEntriesForView(
|
|||||||
|
|
||||||
var contentTypeHint: ChatMessageEntryContentType = .generic
|
var contentTypeHint: ChatMessageEntryContentType = .generic
|
||||||
if presentationData.largeEmoji, topMessage.media.isEmpty {
|
if presentationData.largeEmoji, topMessage.media.isEmpty {
|
||||||
if stickersEnabled && messageIsElligibleForLargeCustomEmoji(topMessage) {
|
if messageIsElligibleForLargeCustomEmoji(topMessage) {
|
||||||
contentTypeHint = .animatedEmoji
|
contentTypeHint = .animatedEmoji
|
||||||
} else if stickersEnabled && topMessage.text.count == 1, let _ = associatedData.animatedEmojiStickers[topMessage.text.basicEmoji.0] {
|
} else if stickersEnabled && topMessage.text.count == 1, let _ = associatedData.animatedEmojiStickers[topMessage.text.basicEmoji.0] {
|
||||||
contentTypeHint = .animatedEmoji
|
contentTypeHint = .animatedEmoji
|
||||||
|
@ -543,17 +543,23 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
|
|
||||||
var emojiFile: TelegramMediaFile?
|
var emojiFile: TelegramMediaFile?
|
||||||
var emojiString: String?
|
var emojiString: String?
|
||||||
if messageIsElligibleForLargeCustomEmoji(item.message) || (item.message.text.count > 1 && messageIsElligibleForLargeEmoji(item.message)) {
|
if messageIsElligibleForLargeCustomEmoji(item.message) || messageIsElligibleForLargeEmoji(item.message) {
|
||||||
emojiString = item.message.text
|
emojiString = item.message.text
|
||||||
}
|
}
|
||||||
|
|
||||||
if emojiFile == nil && emojiString == nil {
|
if emojiFile == nil {
|
||||||
emojiFile = item.associatedData.animatedEmojiStickers[emoji]?.first?.file
|
emojiFile = item.associatedData.animatedEmojiStickers[emoji]?.first?.file
|
||||||
}
|
}
|
||||||
if emojiFile == nil && emojiString == nil {
|
if emojiFile == nil {
|
||||||
emojiFile = item.associatedData.animatedEmojiStickers[emoji.strippedEmoji]?.first?.file
|
emojiFile = item.associatedData.animatedEmojiStickers[emoji.strippedEmoji]?.first?.file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if item.message.text.count == 1 && emojiFile != nil {
|
||||||
|
emojiString = nil
|
||||||
|
} else if emojiString != nil {
|
||||||
|
emojiFile = nil
|
||||||
|
}
|
||||||
|
|
||||||
if self.emojiString != emojiString {
|
if self.emojiString != emojiString {
|
||||||
self.emojiString = emojiString
|
self.emojiString = emojiString
|
||||||
} else if self.emojiFile?.id != emojiFile?.id {
|
} else if self.emojiFile?.id != emojiFile?.id {
|
||||||
@ -953,7 +959,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
}
|
}
|
||||||
} else if let _ = emojiString {
|
} else if let _ = emojiString {
|
||||||
imageVerticalInset = 0.0
|
imageVerticalInset = 0.0
|
||||||
imageTopPadding = 12.0
|
imageTopPadding = 16.0
|
||||||
imageBottomPadding = 20.0
|
imageBottomPadding = 20.0
|
||||||
|
|
||||||
let baseWidth = params.width
|
let baseWidth = params.width
|
||||||
|
Loading…
x
Reference in New Issue
Block a user