From e84fc33aa90f1db02c9952b6b3f250c352c02ff7 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 5 Dec 2025 23:46:46 +0400 Subject: [PATCH] Fix --- .../TelegramEngine/Payments/StarGifts.swift | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift index 266529cfd5..d3dd832a3c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift @@ -3822,32 +3822,34 @@ final class CachedStartGiftUpgradeAttributes: Codable { func _internal_getStarGiftUpgradeAttributes(account: Account, giftId: Int64) -> Signal<[StarGift.UniqueGift.Attribute]?, NoError> { return account.postbox.transaction { transaction in - if let cachedGifts = transaction.retrieveItemCacheEntry(id: giftUpgradesId(giftId: giftId))?.get(CachedStartGiftUpgradeAttributes.self) { - return .single(cachedGifts.attributes) - } else { - return account.network.request(Api.functions.payments.getStarGiftUpgradeAttributes(giftId: giftId)) - |> map(Optional.init) - |> `catch` { _ -> Signal in + let remote = account.network.request(Api.functions.payments.getStarGiftUpgradeAttributes(giftId: giftId)) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) + } + |> mapToSignal { result -> Signal<[StarGift.UniqueGift.Attribute]?, NoError> in + guard let result else { return .single(nil) } - |> mapToSignal { result -> Signal<[StarGift.UniqueGift.Attribute]?, NoError> in - guard let result else { - return .single(nil) - } - switch result { - case let .starGiftUpgradeAttributes(apiAttributes): - let attributes = apiAttributes.compactMap { StarGift.UniqueGift.Attribute(apiAttribute: $0) } - return account.postbox.transaction { transaction in - if !attributes.isEmpty { - if let entry = CodableEntry(CachedStartGiftUpgradeAttributes(attributes: attributes)) { - transaction.putItemCacheEntry(id: giftUpgradesId(giftId: giftId), entry: entry) - } + switch result { + case let .starGiftUpgradeAttributes(apiAttributes): + let attributes = apiAttributes.compactMap { StarGift.UniqueGift.Attribute(apiAttribute: $0) } + return account.postbox.transaction { transaction in + if !attributes.isEmpty { + if let entry = CodableEntry(CachedStartGiftUpgradeAttributes(attributes: attributes)) { + transaction.putItemCacheEntry(id: giftUpgradesId(giftId: giftId), entry: entry) } - return attributes } + return attributes } } } + if let cachedGifts = transaction.retrieveItemCacheEntry(id: giftUpgradesId(giftId: giftId))?.get(CachedStartGiftUpgradeAttributes.self) { + return .single(cachedGifts.attributes) + |> then(remote) + } else { + return remote + } } |> switchToLatest }