Skip to content

Commit e84fc33

Browse files
committed
Fix
1 parent 06cb1ec commit e84fc33

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,32 +3822,34 @@ final class CachedStartGiftUpgradeAttributes: Codable {
38223822

38233823
func _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

Comments
 (0)