mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-06 05:02:54 +00:00
Fix
This commit is contained in:
@@ -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<Api.payments.StarGiftUpgradeAttributes?, NoError> in
|
||||
let remote = account.network.request(Api.functions.payments.getStarGiftUpgradeAttributes(giftId: giftId))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<Api.payments.StarGiftUpgradeAttributes?, NoError> 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user