diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/GiftCodes.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/GiftCodes.swift index 1476796827..96fe6b9258 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/GiftCodes.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/GiftCodes.swift @@ -182,23 +182,27 @@ func _internal_checkPremiumGiftCode(account: Account, slug: String) -> Signal Signal { +public enum ApplyPremiumGiftCodeError { + case generic +} + +func _internal_applyPremiumGiftCode(account: Account, slug: String) -> Signal { return account.network.request(Api.functions.payments.applyGiftCode(slug: slug)) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) + |> mapError { _ -> ApplyPremiumGiftCodeError in + return .generic } - |> mapToSignal { updates -> Signal in - if let updates = updates { - account.stateManager.addUpdates(updates) - } - + |> mapToSignal { updates -> Signal in + account.stateManager.addUpdates(updates) return .complete() } } -func _internal_launchPrepaidGiveaway(account: Account, peerId: EnginePeer.Id, id: Int64, additionalPeerIds: [EnginePeer.Id], countries: [String], onlyNewSubscribers: Bool, randomId: Int64, untilDate: Int32) -> Signal { - return account.postbox.transaction { transaction -> Signal in +public enum LaunchPrepaidGiveawayError { + case generic +} + +func _internal_launchPrepaidGiveaway(account: Account, peerId: EnginePeer.Id, id: Int64, additionalPeerIds: [EnginePeer.Id], countries: [String], onlyNewSubscribers: Bool, randomId: Int64, untilDate: Int32) -> Signal { + return account.postbox.transaction { transaction -> Signal in var flags: Int32 = 0 if onlyNewSubscribers { flags |= (1 << 0) @@ -227,17 +231,15 @@ func _internal_launchPrepaidGiveaway(account: Account, peerId: EnginePeer.Id, id return .complete() } return account.network.request(Api.functions.payments.launchPrepaidGiveaway(peer: inputPeer, giveawayId: id, purpose: .inputStorePaymentPremiumGiveaway(flags: flags, boostPeer: inputPeer, additionalPeers: additionalPeers, countriesIso2: countries, randomId: randomId, untilDate: untilDate, currency: "", amount: 0))) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) + |> mapError { _ -> LaunchPrepaidGiveawayError in + return .generic } - |> mapToSignal { updates -> Signal in - if let updates = updates { - account.stateManager.addUpdates(updates) - } + |> mapToSignal { updates -> Signal in + account.stateManager.addUpdates(updates) return .complete() } } + |> castError(LaunchPrepaidGiveawayError.self) |> switchToLatest } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift index 39b6e91389..d275bc2f26 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift @@ -50,7 +50,7 @@ public extension TelegramEngine { return _internal_checkPremiumGiftCode(account: self.account, slug: slug) } - public func applyPremiumGiftCode(slug: String) -> Signal { + public func applyPremiumGiftCode(slug: String) -> Signal { return _internal_applyPremiumGiftCode(account: self.account, slug: slug) } @@ -62,7 +62,7 @@ public extension TelegramEngine { return _internal_getPremiumGiveawayInfo(account: self.account, peerId: peerId, messageId: messageId) } - public func launchPrepaidGiveaway(peerId: EnginePeer.Id, id: Int64, additionalPeerIds: [EnginePeer.Id], countries: [String], onlyNewSubscribers: Bool, randomId: Int64, untilDate: Int32) -> Signal { + public func launchPrepaidGiveaway(peerId: EnginePeer.Id, id: Int64, additionalPeerIds: [EnginePeer.Id], countries: [String], onlyNewSubscribers: Bool, randomId: Int64, untilDate: Int32) -> Signal { return _internal_launchPrepaidGiveaway(account: self.account, peerId: peerId, id: id, additionalPeerIds: additionalPeerIds, countries: countries, onlyNewSubscribers: onlyNewSubscribers, randomId: randomId, untilDate: untilDate) } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 608e69c87f..0c9ca9bfd4 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -3848,14 +3848,21 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } strongSelf.openResolved(result: .join(joinHash), sourceMessageId: nil) }, openWebView: { [weak self] buttonText, url, simple, source in - guard let strongSelf = self, let peerId = strongSelf.chatLocation.peerId, let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramUser else { + guard let strongSelf = self, let peerId = strongSelf.chatLocation.peerId, let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else { return } strongSelf.chatDisplayNode.dismissInput() - let botName = EnginePeer(peer).displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder) - let botAddress = peer.addressName ?? "" + let botName: String + let botAddress: String + if case let .inline(bot) = source { + botName = bot.compactDisplayTitle + botAddress = bot.addressName ?? "" + } else { + botName = EnginePeer(peer).displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder) + botAddress = peer.addressName ?? "" + } if source == .generic { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, {