From e79e1b2cf90b69cd1e7ac21cf7e802bea4c53f62 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Sun, 29 Jun 2025 18:22:00 +0200 Subject: [PATCH] Update API --- .../SyncCore/SyncCore_Namespaces.swift | 1 + .../Stickers/CachedStickerPack.swift | 29 +++++++++++++++++++ .../Stickers/StickerSetInstallation.swift | 3 ++ 3 files changed, 33 insertions(+) diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_Namespaces.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_Namespaces.swift index 3695c1c33c..78a7f1ddb6 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_Namespaces.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_Namespaces.swift @@ -62,6 +62,7 @@ public struct Namespaces { public static let CloudIconStatusEmoji: Int32 = 10 public static let CloudIconTopicEmoji: Int32 = 11 public static let CloudIconChannelStatusEmoji: Int32 = 12 + public static let CloudTonGifts: Int32 = 13 } public struct OrderedItemList { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift index 5f59f46ce1..0acd1c999b 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift @@ -55,6 +55,9 @@ func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, case .name: namespace = info.id.namespace id = info.id.id + case .tonGifts: + namespace = Namespaces.ItemCollection.CloudTonGifts + id = 0 } if let namespace = namespace, let id = id { transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))), entry: entry) @@ -159,6 +162,20 @@ func _internal_cachedStickerPack(postbox: Postbox, network: Network, reference: } else { return (.fetching, true, nil) } + case .tonGifts: + let namespace = Namespaces.ItemCollection.CloudTonGifts + let id: ItemCollectionId.Id = 0 + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))))?.get(CachedStickerPack.self), let info = cached.info { + previousHash = cached.hash + let current: CachedStickerPackResult = .result(info, cached.items, false) + if cached.hash != info.hash { + return (current, true, previousHash) + } else { + return (current, false, previousHash) + } + } else { + return (.fetching, true, nil) + } case .emojiGenericAnimations: let namespace = Namespaces.ItemCollection.CloudEmojiGenericAnimations let id: ItemCollectionId.Id = 0 @@ -324,6 +341,18 @@ func cachedStickerPack(transaction: Transaction, reference: StickerPackReference if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))))?.get(CachedStickerPack.self), let info = cached.info { return (info, cached.items, false) } + case .tonGifts: + let namespace = Namespaces.ItemCollection.CloudTonGifts + let id: ItemCollectionId.Id = 0 + if let currentInfo = transaction.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: namespace, id: id)) as? StickerPackCollectionInfo { + let items = transaction.getItemCollectionItems(collectionId: ItemCollectionId(namespace: namespace, id: id)) + if !items.isEmpty { + return (StickerPackCollectionInfo.Accessor(currentInfo), items.compactMap { $0 as? StickerPackItem }, true) + } + } + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))))?.get(CachedStickerPack.self), let info = cached.info { + return (info, cached.items, false) + } case .emojiGenericAnimations: let namespace = Namespaces.ItemCollection.CloudEmojiGenericAnimations let id: ItemCollectionId.Id = 0 diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift index db64fe57ab..a806edfb7c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift @@ -58,6 +58,9 @@ func _internal_requestStickerSet(postbox: Postbox, network: Network, reference: case .iconTopicEmoji: collectionId = nil input = .inputStickerSetEmojiDefaultTopicIcons + case .tonGifts: + collectionId = nil + input = .inputStickerSetTonGifts } let localSignal: (ItemCollectionId) -> Signal<(ItemCollectionInfo, [ItemCollectionItem])?, NoError> = { collectionId in