@@ -54,9 +54,13 @@ public enum CachedStickerPackResult {
5454 case result( StickerPackCollectionInfo , [ ItemCollectionItem ] , Bool )
5555}
5656
57- func cacheStickerPack( transaction: Transaction , info: StickerPackCollectionInfo , items: [ ItemCollectionItem ] ) {
57+ func cacheStickerPack( transaction: Transaction , info: StickerPackCollectionInfo , items: [ ItemCollectionItem ] , reference : StickerPackReference ? = nil ) {
5858 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)
5959 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)
60+
61+ if let reference = reference, case . animatedEmoji = reference {
62+ 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)
63+ }
6064}
6165
6266public func cachedStickerPack( postbox: Postbox , network: Network , reference: StickerPackReference , forceRemote: Bool ) -> Signal < CachedStickerPackResult , NoError > {
@@ -76,30 +80,44 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti
7680 let namespace = Namespaces . ItemCollection. CloudStickerPacks
7781 var previousHash : Int32 ?
7882 switch reference {
79- case let . id( id, _) :
80- 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 {
81- previousHash = cached. hash
82- let current : CachedStickerPackResult = . result( info, cached. items, false )
83- if cached. hash != info. hash {
84- return ( current, true , previousHash)
83+ case let . id( id, _) :
84+ 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 {
85+ previousHash = cached. hash
86+ let current : CachedStickerPackResult = . result( info, cached. items, false )
87+ if cached. hash != info. hash {
88+ return ( current, true , previousHash)
89+ } else {
90+ return ( current, true , previousHash)
91+ }
8592 } else {
86- return ( current , true , previousHash )
93+ return ( . fetching , true , nil )
8794 }
88- } else {
89- return ( . fetching , true , nil )
90- }
91- case let . name ( shortName ) :
92- if let cached = transaction . retrieveItemCacheEntry ( id : ItemCacheEntryId ( collectionId : Namespaces . CachedItemCollection . cachedStickerPacks , key : CachedStickerPack . cacheKey ( shortName : shortName ) ) ) as? CachedStickerPack , let info = cached . info {
93- previousHash = cached . hash
94- let current : CachedStickerPackResult = . result ( info , cached . items , false )
95- if cached . hash != info . hash {
96- return ( current , true , previousHash )
95+ case let . name ( shortName ) :
96+ if let cached = transaction . retrieveItemCacheEntry ( id : ItemCacheEntryId ( collectionId : Namespaces . CachedItemCollection . cachedStickerPacks , key : CachedStickerPack . cacheKey ( shortName : shortName ) ) ) as? CachedStickerPack , let info = cached . info {
97+ previousHash = cached . hash
98+ let current : CachedStickerPackResult = . result ( info , cached . items , false )
99+ if cached . hash != info. hash {
100+ return ( current , true , previousHash )
101+ } else {
102+ return ( current , true , previousHash )
103+ }
97104 } else {
98- return ( current, true , previousHash)
105+ return ( . fetching, true , nil )
106+ }
107+ case . animatedEmoji:
108+ let namespace = Namespaces . ItemCollection. CloudAnimatedEmoji
109+ let id : ItemCollectionId . Id = 0
110+ 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 {
111+ previousHash = cached. hash
112+ let current : CachedStickerPackResult = . result( info, cached. items, false )
113+ if cached. hash != info. hash {
114+ return ( current, true , previousHash)
115+ } else {
116+ return ( current, true , previousHash)
117+ }
118+ } else {
119+ return ( . fetching, true , nil )
99120 }
100- } else {
101- return ( . fetching, true , nil )
102- }
103121 }
104122 }
105123 |> mapToSignal { result, loadRemote, previousHash in
@@ -111,10 +129,8 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti
111129 }
112130 return postbox. transaction { transaction -> CachedStickerPackResult in
113131 if let result = result {
114- cacheStickerPack ( transaction: transaction, info: result. 0 , items: result. 1 )
115-
132+ cacheStickerPack ( transaction: transaction, info: result. 0 , items: result. 1 , reference: reference)
116133 let currentInfo = transaction. getItemCollectionInfo ( collectionId: result. 0 . id) as? StickerPackCollectionInfo
117-
118134 return . result( result. 0 , result. 1 , currentInfo != nil )
119135 } else {
120136 return . none
@@ -134,30 +150,42 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti
134150func cachedStickerPack( transaction: Transaction , reference: StickerPackReference ) -> ( StickerPackCollectionInfo , [ ItemCollectionItem ] , Bool ) ? {
135151 let namespace = Namespaces . ItemCollection. CloudStickerPacks
136152 switch reference {
137- case let . id( id, _) :
138- if let currentInfo = transaction. getItemCollectionInfo ( collectionId: ItemCollectionId ( namespace: namespace, id: id) ) as? StickerPackCollectionInfo {
139- let items = transaction. getItemCollectionItems ( collectionId: ItemCollectionId ( namespace: namespace, id: id) )
140- if !items. isEmpty {
141- return ( currentInfo, items, true )
153+ case let . id( id, _) :
154+ if let currentInfo = transaction. getItemCollectionInfo ( collectionId: ItemCollectionId ( namespace: namespace, id: id) ) as? StickerPackCollectionInfo {
155+ let items = transaction. getItemCollectionItems ( collectionId: ItemCollectionId ( namespace: namespace, id: id) )
156+ if !items. isEmpty {
157+ return ( currentInfo, items, true )
158+ }
142159 }
143- }
144- 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 {
145- return ( info , cached . items , false )
146- }
147- case let . name ( shortName ) :
148- for info in transaction . getItemCollectionsInfos ( namespace : namespace ) {
149- if let info = info. 1 as? StickerPackCollectionInfo {
150- if info . shortName == shortName {
151- let items = transaction . getItemCollectionItems ( collectionId : info . id )
152- if ! items. isEmpty {
153- return ( info , items , true )
160+ 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 {
161+ return ( info , cached. items , false )
162+ }
163+ case let . name ( shortName ) :
164+ for info in transaction . getItemCollectionsInfos ( namespace : namespace ) {
165+ if let info = info . 1 as? StickerPackCollectionInfo {
166+ if info. shortName == shortName {
167+ let items = transaction . getItemCollectionItems ( collectionId : info . id )
168+ if !items . isEmpty {
169+ return ( info , items, true )
170+ }
154171 }
155172 }
156173 }
157- }
158- if let cached = transaction. retrieveItemCacheEntry ( id: ItemCacheEntryId ( collectionId: Namespaces . CachedItemCollection. cachedStickerPacks, key: CachedStickerPack . cacheKey ( shortName: shortName) ) ) as? CachedStickerPack , let info = cached. info {
159- return ( info, cached. items, false )
160- }
174+ if let cached = transaction. retrieveItemCacheEntry ( id: ItemCacheEntryId ( collectionId: Namespaces . CachedItemCollection. cachedStickerPacks, key: CachedStickerPack . cacheKey ( shortName: shortName) ) ) as? CachedStickerPack , let info = cached. info {
175+ return ( info, cached. items, false )
176+ }
177+ case . animatedEmoji:
178+ let namespace = Namespaces . ItemCollection. CloudAnimatedEmoji
179+ let id : ItemCollectionId . Id = 0
180+ if let currentInfo = transaction. getItemCollectionInfo ( collectionId: ItemCollectionId ( namespace: namespace, id: id) ) as? StickerPackCollectionInfo {
181+ let items = transaction. getItemCollectionItems ( collectionId: ItemCollectionId ( namespace: namespace, id: id) )
182+ if !items. isEmpty {
183+ return ( currentInfo, items, true )
184+ }
185+ }
186+ 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 {
187+ return ( info, cached. items, false )
188+ }
161189 }
162190 return nil
163191}
0 commit comments