diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift index 022720b8ef..12f5af0a97 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift @@ -97,5 +97,8 @@ public extension TelegramEngine { public func updateStarsSubscription(peerId: EnginePeer.Id, subscriptionId: String, cancel: Bool) -> Signal { return _internal_updateStarsSubscription(account: self.account, peerId: peerId, subscriptionId: subscriptionId, cancel: cancel) } + public func fulfillStarsSubscription(peerId: PeerId, subscriptionId: String) -> Signal { + return _internal_fulfillStarsSubscription(account: self.account, peerId: peerId, subscriptionId: subscriptionId) + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinChannel.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinChannel.swift index df78b66f04..94dacbdc8c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinChannel.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinChannel.swift @@ -17,29 +17,35 @@ func _internal_joinChannel(account: Account, peerId: PeerId, hash: String?) -> S |> take(1) |> castError(JoinChannelError.self) |> mapToSignal { peer -> Signal in - if let inputChannel = apiInputChannel(peer) { - let request: Signal - if let hash = hash { - request = account.network.request(Api.functions.messages.importChatInvite(hash: hash)) - } else { - request = account.network.request(Api.functions.channels.joinChannel(channel: inputChannel)) + + let request: Signal + if let hash = hash { + request = account.network.request(Api.functions.messages.importChatInvite(hash: hash)) + } else if let inputChannel = apiInputChannel(peer) { + request = account.network.request(Api.functions.channels.joinChannel(channel: inputChannel)) + } else { + request = .fail(.init()) + } + + return request + |> mapError { error -> JoinChannelError in + switch error.errorDescription { + case "CHANNELS_TOO_MUCH": + return .tooMuchJoined + case "USERS_TOO_MUCH": + return .tooMuchUsers + case "INVITE_REQUEST_SENT": + return .inviteRequestSent + default: + return .generic } - return request - |> mapError { error -> JoinChannelError in - switch error.errorDescription { - case "CHANNELS_TOO_MUCH": - return .tooMuchJoined - case "USERS_TOO_MUCH": - return .tooMuchUsers - case "INVITE_REQUEST_SENT": - return .inviteRequestSent - default: - return .generic - } - } - |> mapToSignal { updates -> Signal in - account.stateManager.addUpdates(updates) - + } + |> mapToSignal { updates -> Signal in + account.stateManager.addUpdates(updates) + + let channels = updates.chats.compactMap { parseTelegramGroupOrChannel(chat: $0) }.compactMap(apiInputChannel) + + if let inputChannel = channels.first { return account.network.request(Api.functions.channels.getParticipant(channel: inputChannel, participant: .inputPeerSelf)) |> map(Optional.init) |> `catch` { _ -> Signal in @@ -76,14 +82,16 @@ func _internal_joinChannel(account: Account, peerId: PeerId, hash: String?) -> S } |> castError(JoinChannelError.self) } + } else { + return .fail(.generic) } - |> afterCompleted { - if hash == nil { - let _ = _internal_requestRecommendedChannels(account: account, peerId: peerId, forceUpdate: true).startStandalone() - } + + + } + |> afterCompleted { + if hash == nil { + let _ = _internal_requestRecommendedChannels(account: account, peerId: peerId, forceUpdate: true).startStandalone() } - } else { - return .fail(.generic) } } }