@@ -3822,32 +3822,34 @@ final class CachedStartGiftUpgradeAttributes: Codable {
38223822
38233823func _internal_getStarGiftUpgradeAttributes( account: Account , giftId: Int64 ) -> Signal < [ StarGift . UniqueGift . Attribute ] ? , NoError > {
38243824 return account. postbox. transaction { transaction in
3825- if let cachedGifts = transaction. retrieveItemCacheEntry ( id: giftUpgradesId ( giftId: giftId) ) ? . get ( CachedStartGiftUpgradeAttributes . self) {
3826- return . single( cachedGifts. attributes)
3827- } else {
3828- return account. network. request ( Api . functions. payments. getStarGiftUpgradeAttributes ( giftId: giftId) )
3829- |> map ( Optional . init)
3830- |> `catch` { _ -> Signal < Api . payments . StarGiftUpgradeAttributes ? , NoError > in
3825+ let remote = account. network. request ( Api . functions. payments. getStarGiftUpgradeAttributes ( giftId: giftId) )
3826+ |> map ( Optional . init)
3827+ |> `catch` { _ -> Signal < Api . payments . StarGiftUpgradeAttributes ? , NoError > in
3828+ return . single( nil )
3829+ }
3830+ |> mapToSignal { result -> Signal < [ StarGift . UniqueGift . Attribute ] ? , NoError > in
3831+ guard let result else {
38313832 return . single( nil )
38323833 }
3833- |> mapToSignal { result -> Signal < [ StarGift . UniqueGift . Attribute ] ? , NoError > in
3834- guard let result else {
3835- return . single( nil )
3836- }
3837- switch result {
3838- case let . starGiftUpgradeAttributes( apiAttributes) :
3839- let attributes = apiAttributes. compactMap { StarGift . UniqueGift. Attribute ( apiAttribute: $0) }
3840- return account. postbox. transaction { transaction in
3841- if !attributes. isEmpty {
3842- if let entry = CodableEntry ( CachedStartGiftUpgradeAttributes ( attributes: attributes) ) {
3843- transaction. putItemCacheEntry ( id: giftUpgradesId ( giftId: giftId) , entry: entry)
3844- }
3834+ switch result {
3835+ case let . starGiftUpgradeAttributes( apiAttributes) :
3836+ let attributes = apiAttributes. compactMap { StarGift . UniqueGift. Attribute ( apiAttribute: $0) }
3837+ return account. postbox. transaction { transaction in
3838+ if !attributes. isEmpty {
3839+ if let entry = CodableEntry ( CachedStartGiftUpgradeAttributes ( attributes: attributes) ) {
3840+ transaction. putItemCacheEntry ( id: giftUpgradesId ( giftId: giftId) , entry: entry)
38453841 }
3846- return attributes
38473842 }
3843+ return attributes
38483844 }
38493845 }
38503846 }
3847+ if let cachedGifts = transaction. retrieveItemCacheEntry ( id: giftUpgradesId ( giftId: giftId) ) ? . get ( CachedStartGiftUpgradeAttributes . self) {
3848+ return . single( cachedGifts. attributes)
3849+ |> then ( remote)
3850+ } else {
3851+ return remote
3852+ }
38513853 }
38523854 |> switchToLatest
38533855}
0 commit comments