diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index c07fbd6e77..06a2721880 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -538,6 +538,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-4838507] = { return Api.InputStickerSet.parse_inputStickerSetEmpty($0) } dict[-1645763991] = { return Api.InputStickerSet.parse_inputStickerSetID($0) } dict[-2044933984] = { return Api.InputStickerSet.parse_inputStickerSetShortName($0) } + dict[42402760] = { return Api.InputStickerSet.parse_inputStickerSetAnimatedEmoji($0) } dict[-1729618630] = { return Api.BotInfo.parse_botInfo($0) } dict[-1519637954] = { return Api.updates.State.parse_state($0) } dict[372165663] = { return Api.FoundGif.parse_foundGif($0) } diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index 11639e00bd..391a88b56b 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -13607,6 +13607,7 @@ public extension Api { case inputStickerSetEmpty case inputStickerSetID(id: Int64, accessHash: Int64) case inputStickerSetShortName(shortName: String) + case inputStickerSetAnimatedEmoji public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -13628,6 +13629,12 @@ public extension Api { buffer.appendInt32(-2044933984) } serializeString(shortName, buffer: buffer, boxed: false) + break + case .inputStickerSetAnimatedEmoji: + if boxed { + buffer.appendInt32(42402760) + } + break } } @@ -13640,6 +13647,8 @@ public extension Api { return ("inputStickerSetID", [("id", id), ("accessHash", accessHash)]) case .inputStickerSetShortName(let shortName): return ("inputStickerSetShortName", [("shortName", shortName)]) + case .inputStickerSetAnimatedEmoji: + return ("inputStickerSetAnimatedEmoji", []) } } @@ -13671,6 +13680,9 @@ public extension Api { return nil } } + public static func parse_inputStickerSetAnimatedEmoji(_ reader: BufferReader) -> InputStickerSet? { + return Api.InputStickerSet.inputStickerSetAnimatedEmoji + } } public enum BotInfo: TypeConstructorDescription { diff --git a/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift b/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift index b041c7eca2..d31e5e06f7 100644 --- a/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift +++ b/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift @@ -54,9 +54,13 @@ public enum CachedStickerPackResult { case result(StickerPackCollectionInfo, [ItemCollectionItem], Bool) } -func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, items: [ItemCollectionItem]) { +func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, items: [ItemCollectionItem], reference: StickerPackReference? = nil) { transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id)), entry: CachedStickerPack(info: info, items: items.map { $0 as! StickerPackItem }, hash: info.hash), collectionSpec: collectionSpec) transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName)), entry: CachedStickerPack(info: info, items: items.map { $0 as! StickerPackItem }, hash: info.hash), collectionSpec: collectionSpec) + + if let reference = reference, case .animatedEmoji = reference { + transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: Namespaces.ItemCollection.CloudAnimatedEmoji, id: 0))), entry: CachedStickerPack(info: info, items: items.map { $0 as! StickerPackItem }, hash: info.hash), collectionSpec: collectionSpec) + } } public func cachedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference, forceRemote: Bool) -> Signal { @@ -76,30 +80,44 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti let namespace = Namespaces.ItemCollection.CloudStickerPacks var previousHash: Int32? switch reference { - case let .id(id, _): - if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { - previousHash = cached.hash - let current: CachedStickerPackResult = .result(info, cached.items, false) - if cached.hash != info.hash { - return (current, true, previousHash) + case let .id(id, _): + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, 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, true, previousHash) + } } else { - return (current, true, previousHash) + return (.fetching, true, nil) } - } else { - return (.fetching, true, nil) - } - case let .name(shortName): - if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: shortName))) as? CachedStickerPack, let info = cached.info { - previousHash = cached.hash - let current: CachedStickerPackResult = .result(info, cached.items, false) - if cached.hash != info.hash { - return (current, true, previousHash) + case let .name(shortName): + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: shortName))) as? CachedStickerPack, 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, true, previousHash) + } } else { - return (current, true, previousHash) + return (.fetching, true, nil) + } + case .animatedEmoji: + let namespace = Namespaces.ItemCollection.CloudAnimatedEmoji + let id: ItemCollectionId.Id = 0 + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, 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, true, previousHash) + } + } else { + return (.fetching, true, nil) } - } else { - return (.fetching, true, nil) - } } } |> mapToSignal { result, loadRemote, previousHash in @@ -111,10 +129,8 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti } return postbox.transaction { transaction -> CachedStickerPackResult in if let result = result { - cacheStickerPack(transaction: transaction, info: result.0, items: result.1) - + cacheStickerPack(transaction: transaction, info: result.0, items: result.1, reference: reference) let currentInfo = transaction.getItemCollectionInfo(collectionId: result.0.id) as? StickerPackCollectionInfo - return .result(result.0, result.1, currentInfo != nil) } else { return .none @@ -134,30 +150,42 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti func cachedStickerPack(transaction: Transaction, reference: StickerPackReference) -> (StickerPackCollectionInfo, [ItemCollectionItem], Bool)? { let namespace = Namespaces.ItemCollection.CloudStickerPacks switch reference { - case let .id(id, _): - 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 (currentInfo, items, true) + case let .id(id, _): + 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 (currentInfo, items, true) + } } - } - if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { - return (info, cached.items, false) - } - case let .name(shortName): - for info in transaction.getItemCollectionsInfos(namespace: namespace) { - if let info = info.1 as? StickerPackCollectionInfo { - if info.shortName == shortName { - let items = transaction.getItemCollectionItems(collectionId: info.id) - if !items.isEmpty { - return (info, items, true) + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { + return (info, cached.items, false) + } + case let .name(shortName): + for info in transaction.getItemCollectionsInfos(namespace: namespace) { + if let info = info.1 as? StickerPackCollectionInfo { + if info.shortName == shortName { + let items = transaction.getItemCollectionItems(collectionId: info.id) + if !items.isEmpty { + return (info, items, true) + } } } } - } - if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: shortName))) as? CachedStickerPack, let info = cached.info { - return (info, cached.items, false) - } + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: shortName))) as? CachedStickerPack, let info = cached.info { + return (info, cached.items, false) + } + case .animatedEmoji: + let namespace = Namespaces.ItemCollection.CloudAnimatedEmoji + 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 (currentInfo, items, true) + } + } + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { + return (info, cached.items, false) + } } return nil } diff --git a/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift b/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift index a2c7843238..05b0385db8 100644 --- a/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift +++ b/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift @@ -20,6 +20,8 @@ extension StickerPackReference { return .inputStickerSetID(id: id, accessHash: accessHash) case let .name(name): return .inputStickerSetShortName(shortName: name) + case .animatedEmoji: + return .inputStickerSetAnimatedEmoji } } } diff --git a/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift index 861c0607df..e7dd9f46a1 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift @@ -504,6 +504,8 @@ private func decryptedAttributes46(_ attributes: [TelegramMediaFileAttribute], t if let (info, _, _) = cachedStickerPack(transaction: transaction, reference: packReference) { stickerSet = .inputStickerSetShortName(shortName: info.shortName) } + default: + stickerSet = .inputStickerSetEmpty } } result.append(.documentAttributeSticker(alt: displayText, stickerset: stickerSet)) @@ -553,6 +555,8 @@ private func decryptedAttributes73(_ attributes: [TelegramMediaFileAttribute], t if let (info, _, _) = cachedStickerPack(transaction: transaction, reference: packReference) { stickerSet = .inputStickerSetShortName(shortName: info.shortName) } + default: + stickerSet = .inputStickerSetEmpty } } result.append(.documentAttributeSticker(alt: displayText, stickerset: stickerSet)) @@ -600,12 +604,14 @@ private func decryptedAttributes101(_ attributes: [TelegramMediaFileAttribute], var stickerSet: SecretApi101.InputStickerSet = .inputStickerSetEmpty if let packReference = packReference { switch packReference { - case let .name(name): - stickerSet = .inputStickerSetShortName(shortName: name) - case .id: - if let (info, _, _) = cachedStickerPack(transaction: transaction, reference: packReference) { - stickerSet = .inputStickerSetShortName(shortName: info.shortName) - } + case let .name(name): + stickerSet = .inputStickerSetShortName(shortName: name) + case .id: + if let (info, _, _) = cachedStickerPack(transaction: transaction, reference: packReference) { + stickerSet = .inputStickerSetShortName(shortName: info.shortName) + } + default: + stickerSet = .inputStickerSetEmpty } } result.append(.documentAttributeSticker(alt: displayText, stickerset: stickerSet)) diff --git a/submodules/TelegramCore/TelegramCore/Namespaces.swift b/submodules/TelegramCore/TelegramCore/Namespaces.swift index 76df73b2ee..367b947145 100644 --- a/submodules/TelegramCore/TelegramCore/Namespaces.swift +++ b/submodules/TelegramCore/TelegramCore/Namespaces.swift @@ -42,6 +42,7 @@ public struct Namespaces { public static let CloudStickerPacks: Int32 = 0 public static let CloudMaskPacks: Int32 = 1 public static let EmojiKeywords: Int32 = 2 + public static let CloudAnimatedEmoji: Int32 = 3 } public struct OrderedItemList { diff --git a/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift b/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift index c2df28501e..d4a62c5ba5 100644 --- a/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift +++ b/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift @@ -417,6 +417,8 @@ func inputDocumentAttributesFromFileAttributes(_ fileAttributes: [TelegramMediaF stickerSet = .inputStickerSetID(id: id, accessHash: accessHash) case let .name(name): stickerSet = .inputStickerSetShortName(shortName: name) + default: + stickerSet = .inputStickerSetEmpty } } var inputMaskCoords: Api.MaskCoords? diff --git a/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift b/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift index a22a100c4c..f1c18c9545 100644 --- a/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift +++ b/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift @@ -39,6 +39,9 @@ public func requestStickerSet(postbox: Postbox, network: Network, reference: Sti case let .id(id, accessHash): collectionId = ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id) input = .inputStickerSetID(id: id, accessHash: accessHash) + case .animatedEmoji: + collectionId = nil + input = .inputStickerSetAnimatedEmoji } let localSignal: (ItemCollectionId) -> Signal<(ItemCollectionInfo, [ItemCollectionItem])?, NoError> = { collectionId in diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift index 7e985d73da..284361edd5 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift @@ -128,6 +128,8 @@ public func addSavedSticker(postbox: Postbox, network: Network, file: TelegramMe if !found { fetchReference = packReference } + case .animatedEmoji: + break } if let fetchReference = fetchReference { return network.request(Api.functions.messages.getStickerSet(stickerset: fetchReference.apiInputStickerSet)) diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift index 57b2b4297e..b475a37ca9 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift @@ -20,6 +20,7 @@ private let typeHasLinkedStickers: Int32 = 6 public enum StickerPackReference: PostboxCoding, Hashable, Equatable { case id(id: Int64, accessHash: Int64) case name(String) + case animatedEmoji public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("r", orElse: 0) { @@ -27,6 +28,8 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { self = .id(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) case 1: self = .name(decoder.decodeStringForKey("n", orElse: "")) + case 2: + self = .animatedEmoji default: self = .name("") assertionFailure() @@ -42,6 +45,8 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { case let .name(name): encoder.encodeInt32(1, forKey: "r") encoder.encodeString(name, forKey: "n") + case .animatedEmoji: + encoder.encodeInt32(2, forKey: "r") } } @@ -59,6 +64,12 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { } else { return false } + case .animatedEmoji: + if case .animatedEmoji = rhs { + return true + } else { + return false + } } } } @@ -510,6 +521,8 @@ extension StickerPackReference { self = .id(id: id, accessHash: accessHash) case let .inputStickerSetShortName(shortName): self = .name(shortName) + case .inputStickerSetAnimatedEmoji: + self = .animatedEmoji } } }