Separate channel voice chat localization

This commit is contained in:
Ali 2021-08-29 18:13:57 +04:00
parent eab8e7cf68
commit 235934ae8a
6 changed files with 82 additions and 23 deletions

View File

@ -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 %@.";

View File

@ -265,20 +265,31 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder {
let availableGroupCall: Signal<GroupCallPanelData?, NoError>
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<GroupCallPanelData?, NoError> in
|> distinctUntilChanged(isEqual: { lhs, rhs in
if lhs.0 != rhs.0 {
return false
}
return true
})
|> mapToSignal { activeCall, peer -> Signal<GroupCallPanelData?, NoError> 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()

View File

@ -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

View File

@ -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<Bool, NoError> in
|> mapToSignal { [weak self] accessEnabled, peer -> Signal<Bool, NoError> 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<Bool, NoError> in
|> mapToSignal { [weak self] accessEnabled, peer -> Signal<Bool, NoError> 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
)

View File

@ -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<GroupCallParticipantsContext.State?, NoError> 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<GroupCallParticipantsContext.State?, NoError> 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 {

View File

@ -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
}
}
}
}