Various improvements

This commit is contained in:
Ilya Laktyushin
2023-12-16 15:57:24 +04:00
parent a3126f87a0
commit 7d45c4c9d0
80 changed files with 2816 additions and 1065 deletions

View File

@@ -6,7 +6,7 @@ import TelegramApi
public struct PremiumGiftCodeInfo: Equatable {
public let slug: String
public let fromPeerId: EnginePeer.Id
public let fromPeerId: EnginePeer.Id?
public let messageId: EngineMessage.Id?
public let toPeerId: EnginePeer.Id?
public let date: Int32
@@ -191,11 +191,19 @@ func _internal_checkPremiumGiftCode(account: Account, slug: String) -> Signal<Pr
public enum ApplyPremiumGiftCodeError {
case generic
case waitForExpiration(Int32)
}
func _internal_applyPremiumGiftCode(account: Account, slug: String) -> Signal<Never, ApplyPremiumGiftCodeError> {
return account.network.request(Api.functions.payments.applyGiftCode(slug: slug))
|> mapError { _ -> ApplyPremiumGiftCodeError in
|> mapError { error -> ApplyPremiumGiftCodeError in
if error.errorDescription.hasPrefix("FLOOD_WAIT_") {
if let range = error.errorDescription.range(of: "_", options: .backwards) {
if let value = Int32(error.errorDescription[range.upperBound...]) {
return .waitForExpiration(value)
}
}
}
return .generic
}
|> mapToSignal { updates -> Signal<Never, ApplyPremiumGiftCodeError> in
@@ -266,8 +274,12 @@ extension PremiumGiftCodeInfo {
switch apiCheckedGiftCode {
case let .checkedGiftCode(flags, fromId, giveawayMsgId, toId, date, months, usedDate, _, _):
self.slug = slug
self.fromPeerId = fromId.peerId
self.messageId = giveawayMsgId.flatMap { EngineMessage.Id(peerId: fromId.peerId, namespace: Namespaces.Message.Cloud, id: $0) }
self.fromPeerId = fromId?.peerId
if let fromId = fromId, let giveawayMsgId = giveawayMsgId {
self.messageId = EngineMessage.Id(peerId: fromId.peerId, namespace: Namespaces.Message.Cloud, id: giveawayMsgId)
} else {
self.messageId = nil
}
self.toPeerId = toId.flatMap { EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value($0)) }
self.date = date
self.months = months