diff --git a/submodules/TelegramCore/Sources/MacOS/MacInternalUpdater.swift b/submodules/TelegramCore/Sources/MacOS/MacInternalUpdater.swift index 774b18901c..afa55aabb5 100644 --- a/submodules/TelegramCore/Sources/MacOS/MacInternalUpdater.swift +++ b/submodules/TelegramCore/Sources/MacOS/MacInternalUpdater.swift @@ -30,7 +30,7 @@ public func requestUpdatesXml(account: Account, source: String) -> Signal mapToSignal { result in switch result { case let .channelMessages(_, _, _, _, apiMessages, _, apiChats, apiUsers): - if let apiMessage = apiMessages.first, let storeMessage = StoreMessage(apiMessage: apiMessage, peerIsForum: peer.isForum) { + if let apiMessage = apiMessages.first, let storeMessage = StoreMessage(apiMessage: apiMessage, accountPeerId: account.peerId, peerIsForum: peer.isForum) { var peers: [PeerId: Peer] = [:] for chat in apiChats { @@ -113,7 +113,7 @@ public func downloadAppUpdate(account: Account, source: String, messageId: Int32 } let messageAndFile:(Message, TelegramMediaFile)? = apiMessages.compactMap { value in - return StoreMessage(apiMessage: value, peerIsForum: peer.isForum) + return StoreMessage(apiMessage: value, accountPeerId: account.peerId, peerIsForum: peer.isForum) }.compactMap { value in return locallyRenderedMessage(message: value, peers: peers) }.sorted(by: { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift index 3084c30fb3..f2b7778434 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift @@ -8,6 +8,7 @@ public enum BotPaymentInvoiceSource { case message(MessageId) case slug(String) case premiumGiveaway(boostPeer: EnginePeer.Id, additionalPeerIds: [EnginePeer.Id], countries: [String], onlyNewSubscribers: Bool, showWinners: Bool, prizeDescription: String?, randomId: Int64, untilDate: Int32, currency: String, amount: Int64, option: PremiumGiftCodeOption) + case giftCode(users: [PeerId], currency: String, amount: Int64, option: PremiumGiftCodeOption) } @@ -255,6 +256,33 @@ private func _internal_parseInputInvoice(transaction: Transaction, source: BotPa let option: Api.PremiumGiftCodeOption = .premiumGiftCodeOption(flags: flags, users: option.users, months: option.months, storeProduct: option.storeProductId, storeQuantity: option.storeQuantity, currency: option.currency, amount: option.amount) return .inputInvoicePremiumGiftCode(purpose: inputPurpose, option: option) + case let .giftCode(users, currency, amount, option): + + + var inputUsers: [Api.InputUser] = [] + if !users.isEmpty { + for peerId in users { + if let peer = transaction.getPeer(peerId), let inputPeer = apiInputUser(peer) { + inputUsers.append(inputPeer) + } + } + } + + let inputPurpose: Api.InputStorePaymentPurpose = .inputStorePaymentPremiumGiftCode(flags: 0, users: inputUsers, boostPeer: nil, currency: currency, amount: amount) + + + var flags: Int32 = 0 + if let _ = option.storeProductId { + flags |= (1 << 0) + } + if option.storeQuantity > 0 { + flags |= (1 << 1) + } + + let option: Api.PremiumGiftCodeOption = .premiumGiftCodeOption(flags: flags, users: option.users, months: option.months, storeProduct: option.storeProductId, storeQuantity: option.storeQuantity, currency: option.currency, amount: option.amount) + + return .inputInvoicePremiumGiftCode(purpose: inputPurpose, option: option) + } } @@ -539,6 +567,8 @@ func _internal_sendBotPaymentForm(account: Account, formId: Int64, source: BotPa receiptMessageId = id } } + case .giftCode: + receiptMessageId = nil } } }