diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index cebb7c9e12..809713bb62 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -5719,6 +5719,7 @@ Sorry for the inconvenience."; "VoiceChat.PanelJoin" = "Join"; "VoiceChat.Title" = "Voice Chat"; +"VoiceChatChannel.Title" = "Live Stream"; "VoiceChat.InviteMember" = "Invite Member"; "VoiceChat.UserInvited" = "You invited **%@** to the voice chat"; @@ -6365,6 +6366,7 @@ Sorry for the inconvenience."; "ChannelInfo.ScheduleVoiceChat" = "Schedule Voice Chat"; "ScheduleVoiceChat.Title" = "Schedule Voice Chat"; +"ScheduleVoiceChatChannel.Title" = "Schedule Voice Chat"; "ScheduleVoiceChat.GroupText" = "The members of the group will be notified that the voice chat will start in %@."; "ScheduleVoiceChat.ChannelText" = "The members of the channel will be notified that the voice chat will start in %@."; diff --git a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift index b757ba1544..a1848a92fe 100644 --- a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift +++ b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift @@ -265,20 +265,31 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder { let availableGroupCall: Signal if case let .peer(peerId) = groupCallPanelSource { availableGroupCall = context.account.viewTracker.peerView(peerId) - |> map { peerView -> CachedChannelData.ActiveCall? in + |> map { peerView -> (CachedChannelData.ActiveCall?, EnginePeer?) in + let peer = peerView.peers[peerId].flatMap(EnginePeer.init) if let cachedData = peerView.cachedData as? CachedChannelData { - return cachedData.activeCall + return (cachedData.activeCall, peer) } else if let cachedData = peerView.cachedData as? CachedGroupData { - return cachedData.activeCall + return (cachedData.activeCall, peer) } else { - return nil + return (nil, peer) } } - |> distinctUntilChanged - |> mapToSignal { activeCall -> Signal in + |> distinctUntilChanged(isEqual: { lhs, rhs in + if lhs.0 != rhs.0 { + return false + } + return true + }) + |> mapToSignal { activeCall, peer -> Signal in guard let activeCall = activeCall else { return .single(nil) } + + var isChannel = false + if let peer = peer, case let .channel(channel) = peer, case .broadcast = channel.info { + isChannel = true + } return Signal { [weak context] subscriber in guard let context = context, let callContextCache = context.cachedGroupCallContexts as? AccountGroupCallContextCacheImpl else { @@ -288,7 +299,7 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder { let disposable = MetaDisposable() callContextCache.impl.syncWith { impl in - let callContext = impl.get(account: context.account, engine: context.engine, peerId: peerId, call: EngineGroupCallDescription(activeCall)) + let callContext = impl.get(account: context.account, engine: context.engine, peerId: peerId, isChannel: isChannel, call: EngineGroupCallDescription(activeCall)) disposable.set((callContext.context.panelData |> deliverOnMainQueue).start(next: { panelData in callContext.keep() diff --git a/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift b/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift index 91736b1655..617d4505db 100644 --- a/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift +++ b/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift @@ -40,6 +40,7 @@ public enum GroupCallPanelSource { public final class GroupCallPanelData { public let peerId: PeerId + public let isChannel: Bool public let info: GroupCallInfo public let topParticipants: [GroupCallParticipantsContext.Participant] public let participantCount: Int @@ -48,6 +49,7 @@ public final class GroupCallPanelData { public init( peerId: PeerId, + isChannel: Bool, info: GroupCallInfo, topParticipants: [GroupCallParticipantsContext.Participant], participantCount: Int, @@ -55,6 +57,7 @@ public final class GroupCallPanelData { groupCall: PresentationGroupCall? ) { self.peerId = peerId + self.isChannel = isChannel self.info = info self.topParticipants = topParticipants self.participantCount = participantCount @@ -523,6 +526,9 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode { var joinText = self.strings.VoiceChat_PanelJoin var title = self.strings.VoiceChat_Title + if let currentData = self.currentData, currentData.isChannel { + title = self.strings.VoiceChatChannel_Title + } var text = self.currentText var isScheduled = false var isLate = false diff --git a/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift b/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift index b1be092676..0769584735 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift @@ -650,9 +650,12 @@ public final class PresentationCallManagerImpl: PresentationCallManager { } |> runOn(Queue.mainQueue()) - return accessEnabledSignal + return combineLatest(queue: .mainQueue(), + accessEnabledSignal, + accountContext.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) + ) |> deliverOnMainQueue - |> mapToSignal { [weak self] accessEnabled -> Signal in + |> mapToSignal { [weak self] accessEnabled, peer -> Signal in guard let strongSelf = self else { return .single(false) } @@ -660,6 +663,11 @@ public final class PresentationCallManagerImpl: PresentationCallManager { if !accessEnabled { return .single(false) } + + var isChannel = false + if let peer = peer, case let .channel(channel) = peer, case .broadcast = channel.info { + isChannel = true + } let call = PresentationGroupCallImpl( accountContext: accountContext, @@ -669,6 +677,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager { initialCall: nil, internalId: internalId, peerId: peerId, + isChannel: isChannel, invite: nil, joinAsPeerId: nil ) @@ -803,9 +812,12 @@ public final class PresentationCallManagerImpl: PresentationCallManager { } |> runOn(Queue.mainQueue()) - return accessEnabledSignal + return combineLatest(queue: .mainQueue(), + accessEnabledSignal, + accountContext.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) + ) |> deliverOnMainQueue - |> mapToSignal { [weak self] accessEnabled -> Signal in + |> mapToSignal { [weak self] accessEnabled, peer -> Signal in guard let strongSelf = self else { return .single(false) } @@ -813,6 +825,11 @@ public final class PresentationCallManagerImpl: PresentationCallManager { if !accessEnabled { return .single(false) } + + var isChannel = false + if let peer = peer, case let .channel(channel) = peer, case .broadcast = channel.info { + isChannel = true + } let call = PresentationGroupCallImpl( accountContext: accountContext, @@ -822,6 +839,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager { initialCall: initialCall, internalId: internalId, peerId: peerId, + isChannel: isChannel, invite: invite, joinAsPeerId: joinAsPeerId ) diff --git a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift index 4071824367..1b3b041458 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift @@ -91,9 +91,10 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext { return self.panelDataPromise.get() } - public init(account: Account, engine: TelegramEngine, peerId: PeerId, call: EngineGroupCallDescription) { + public init(account: Account, engine: TelegramEngine, peerId: PeerId, isChannel: Bool, call: EngineGroupCallDescription) { self.panelDataPromise.set(.single(GroupCallPanelData( peerId: peerId, + isChannel: isChannel, info: GroupCallInfo( id: call.id, accessHash: call.accessHash, @@ -113,13 +114,18 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext { activeSpeakers: Set(), groupCall: nil ))) + + let state = engine.calls.getGroupCallParticipants(callId: call.id, accessHash: call.accessHash, offset: "", ssrcs: [], limit: 100, sortAscending: nil) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) + } - self.disposable = (engine.calls.getGroupCallParticipants(callId: call.id, accessHash: call.accessHash, offset: "", ssrcs: [], limit: 100, sortAscending: nil) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> deliverOnMainQueue).start(next: { [weak self] state in + self.disposable = (combineLatest(queue: .mainQueue(), + state, + engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) + ) + |> deliverOnMainQueue).start(next: { [weak self] state, peer in guard let strongSelf = self, let state = state else { return } @@ -145,8 +151,15 @@ public final class AccountGroupCallContextImpl: AccountGroupCallContext { } topParticipants.append(participant) } + + var isChannel = false + if let peer = peer, case let .channel(channel) = peer, case .broadcast = channel.info { + isChannel = true + } + return GroupCallPanelData( peerId: peerId, + isChannel: isChannel, info: GroupCallInfo(id: call.id, accessHash: call.accessHash, participantCount: state.totalCount, streamDcId: nil, title: state.title, scheduleTimestamp: state.scheduleTimestamp, subscribedToScheduled: state.subscribedToScheduled, recordingStartTimestamp: nil, sortAscending: state.sortAscending, defaultParticipantsAreMuted: state.defaultParticipantsAreMuted, isVideoEnabled: state.isVideoEnabled, unmutedVideoLimit: state.unmutedVideoLimit), topParticipants: topParticipants, participantCount: state.totalCount, @@ -183,12 +196,12 @@ public final class AccountGroupCallContextCacheImpl: AccountGroupCallContextCach self.queue = queue } - public func get(account: Account, engine: TelegramEngine, peerId: PeerId, call: EngineGroupCallDescription) -> AccountGroupCallContextImpl.Proxy { + public func get(account: Account, engine: TelegramEngine, peerId: PeerId, isChannel: Bool, call: EngineGroupCallDescription) -> AccountGroupCallContextImpl.Proxy { let result: Record if let current = self.contexts[call.id] { result = current } else { - let context = AccountGroupCallContextImpl(account: account, engine: engine, peerId: peerId, call: call) + let context = AccountGroupCallContextImpl(account: account, engine: engine, peerId: peerId, isChannel: isChannel, call: call) result = Record(context: context) self.contexts[call.id] = result } @@ -624,6 +637,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { initialCall: EngineGroupCallDescription?, internalId: CallSessionInternalId, peerId: PeerId, + isChannel: Bool, invite: String?, joinAsPeerId: PeerId? ) { @@ -822,7 +836,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { }) if let initialCall = initialCall, let temporaryParticipantsContext = (self.accountContext.cachedGroupCallContexts as? AccountGroupCallContextCacheImpl)?.impl.syncWith({ impl in - impl.get(account: accountContext.account, engine: accountContext.engine, peerId: peerId, call: EngineGroupCallDescription(id: initialCall.id, accessHash: initialCall.accessHash, title: initialCall.title, scheduleTimestamp: initialCall.scheduleTimestamp, subscribedToScheduled: initialCall.subscribedToScheduled)) + impl.get(account: accountContext.account, engine: accountContext.engine, peerId: peerId, isChannel: isChannel, call: EngineGroupCallDescription(id: initialCall.id, accessHash: initialCall.accessHash, title: initialCall.title, scheduleTimestamp: initialCall.scheduleTimestamp, subscribedToScheduled: initialCall.subscribedToScheduled)) }) { self.switchToTemporaryParticipantsContext(sourceContext: temporaryParticipantsContext.context.participantsContext, oldMyPeerId: self.joinAsPeerId) } else { diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 869fdd3dc1..f55535c18d 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -3920,12 +3920,20 @@ public final class VoiceChatController: ViewController { var title = self.currentTitle if self.isScheduling { - title = self.presentationData.strings.ScheduleVoiceChat_Title + if let peer = self.peer as? TelegramChannel, case .broadcast = peer.info { + title = self.presentationData.strings.ScheduleVoiceChatChannel_Title + } else { + title = self.presentationData.strings.ScheduleVoiceChat_Title + } } else if case .modal(_, false) = self.displayMode, !self.currentTitleIsCustom { if let navigationController = self.controller?.navigationController as? NavigationController { for controller in navigationController.viewControllers.reversed() { if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation, peerId == self.call.peerId { - title = self.presentationData.strings.VoiceChat_Title + if let peer = self.peer as? TelegramChannel, case .broadcast = peer.info { + title = self.presentationData.strings.VoiceChatChannel_Title + } else { + title = self.presentationData.strings.VoiceChat_Title + } } } }