mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
burned flag
This commit is contained in:
parent
609c22582a
commit
15d0267e72
2 changed files with 28 additions and 20 deletions
|
|
@ -426,6 +426,7 @@ public enum StarGift: Equatable, Codable, PostboxCoding {
|
|||
}
|
||||
|
||||
public static let isThemeAvailable = Flags(rawValue: 1 << 0)
|
||||
public static let isBurned = Flags(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
public enum Attribute: Equatable, Codable, PostboxCoding {
|
||||
|
|
@ -1308,13 +1309,16 @@ extension StarGift {
|
|||
} else if let ownerName {
|
||||
owner = .name(ownerName)
|
||||
} else {
|
||||
owner = nil
|
||||
owner = .none
|
||||
}
|
||||
let resellAmounts = apiResellAmount?.compactMap { CurrencyAmount(apiAmount: $0) }
|
||||
var flags = StarGift.UniqueGift.Flags()
|
||||
if (apiFlags & (1 << 9)) != 0 {
|
||||
flags.insert(.isThemeAvailable)
|
||||
}
|
||||
if (apiFlags & (1 << 14)) != 0 {
|
||||
flags.insert(.isBurned)
|
||||
}
|
||||
var peerCollectibleColor: PeerCollectibleColor?
|
||||
switch peerColor {
|
||||
case let .peerColorCollectible(peerColorCollectibleData):
|
||||
|
|
@ -3589,28 +3593,32 @@ extension StarGift.UniqueGift.Attribute {
|
|||
}
|
||||
|
||||
|
||||
func _internal_getUniqueStarGift(account: Account, slug: String) -> Signal<StarGift.UniqueGift?, NoError> {
|
||||
public enum GetUniqueStarGiftError {
|
||||
case generic
|
||||
case burned
|
||||
}
|
||||
|
||||
func _internal_getUniqueStarGift(account: Account, slug: String) -> Signal<StarGift.UniqueGift?, GetUniqueStarGiftError> {
|
||||
return account.network.request(Api.functions.payments.getUniqueStarGift(slug: slug))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<Api.payments.UniqueStarGift?, NoError> in
|
||||
return .single(nil)
|
||||
|> mapError { error -> GetUniqueStarGiftError in
|
||||
if error.errorDescription == "STARGIFT_ALREADY_BURNED" {
|
||||
return .burned
|
||||
}
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { result -> Signal<StarGift.UniqueGift?, NoError> in
|
||||
if let result = result {
|
||||
switch result {
|
||||
case let .uniqueStarGift(uniqueStarGiftData):
|
||||
let (gift, chats, users) = (uniqueStarGiftData.gift, uniqueStarGiftData.chats, uniqueStarGiftData.users)
|
||||
return account.postbox.transaction { transaction in
|
||||
let parsedPeers = AccumulatedPeers(chats: chats, users: users)
|
||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers)
|
||||
guard case let .unique(uniqueGift) = StarGift(apiStarGift: gift) else {
|
||||
return nil
|
||||
}
|
||||
return uniqueGift
|
||||
|> mapToSignal { result -> Signal<StarGift.UniqueGift?, GetUniqueStarGiftError> in
|
||||
switch result {
|
||||
case let .uniqueStarGift(uniqueStarGiftData):
|
||||
let (gift, chats, users) = (uniqueStarGiftData.gift, uniqueStarGiftData.chats, uniqueStarGiftData.users)
|
||||
return account.postbox.transaction { transaction in
|
||||
let parsedPeers = AccumulatedPeers(chats: chats, users: users)
|
||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers)
|
||||
guard case let .unique(uniqueGift) = StarGift(apiStarGift: gift) else {
|
||||
return nil
|
||||
}
|
||||
return uniqueGift
|
||||
}
|
||||
} else {
|
||||
return .single(nil)
|
||||
|> castError(GetUniqueStarGiftError.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public extension TelegramEngine {
|
|||
return _internal_checkCanSendStarGift(account: self.account, giftId: giftId)
|
||||
}
|
||||
|
||||
public func getUniqueStarGift(slug: String) -> Signal<StarGift.UniqueGift?, NoError> {
|
||||
public func getUniqueStarGift(slug: String) -> Signal<StarGift.UniqueGift?, GetUniqueStarGiftError> {
|
||||
return _internal_getUniqueStarGift(account: self.account, slug: slug)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue