From 4e412660733d4d46c95ff137adafa7b0b19edec2 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 7 Mar 2021 09:31:07 +0400 Subject: [PATCH 1/2] Add raised hand voice chat participant status --- .../Sources/VoiceChatController.swift | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 50423bb6b1..3f8a297c85 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -370,6 +370,7 @@ public final class VoiceChatController: ViewController { case listening case speaking case invited + case raisedHand } var peer: Peer @@ -383,7 +384,6 @@ public final class VoiceChatController: ViewController { var revealed: Bool? var canManageCall: Bool var volume: Int32? - var raiseHandStatus: Bool var stableId: PeerId { return self.peer.id @@ -423,9 +423,6 @@ public final class VoiceChatController: ViewController { if lhs.volume != rhs.volume { return false } - if lhs.raiseHandStatus != rhs.raiseHandStatus { - return false - } return true } @@ -523,12 +520,10 @@ public final class VoiceChatController: ViewController { let icon: VoiceChatParticipantItem.Icon switch peerEntry.state { case .listening: - var isAbout = false if let muteState = peerEntry.muteState, muteState.mutedByYou { text = .text(presentationData.strings.VoiceChat_StatusMutedForYou, .destructive) } else if let about = peerEntry.about, !about.isEmpty { text = .text(about, .generic) - isAbout = true } else { text = .text(presentationData.strings.VoiceChat_StatusListening, .generic) } @@ -555,12 +550,11 @@ public final class VoiceChatController: ViewController { case .invited: text = .text(presentationData.strings.VoiceChat_StatusInvited, .generic) icon = .invite(true) + case .raisedHand: + text = .text(presentationData.strings.VoiceChat_StatusWantsToSpeak, .accent) + icon = .invite(true) } - - if peerEntry.raiseHandStatus, case let .text(value, type) = text { - text = .text("[hand] \(value)", type) - } - + let revealOptions: [VoiceChatParticipantItem.RevealOption] = [] return VoiceChatParticipantItem(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, context: context, peer: peer, ssrc: peerEntry.ssrc, presence: peerEntry.presence, text: text, icon: icon, enabled: true, selectable: !peerEntry.isMyPeer || peerEntry.canManageCall, getAudioLevel: { return interaction.getAudioLevel(peer.id) }, getVideo: { @@ -2748,7 +2742,10 @@ public final class VoiceChatController: ViewController { let memberState: PeerEntry.State var memberMuteState: GroupCallParticipantsContext.Participant.MuteState? - if member.peer.id == self.callState?.myPeerId { + if member.raiseHandRating != nil { + memberState = .raisedHand + memberMuteState = member.muteState + } else if member.peer.id == self.callState?.myPeerId { if muteState == nil { memberState = speakingPeers.contains(member.peer.id) ? .speaking : .listening } else { @@ -2770,8 +2767,7 @@ public final class VoiceChatController: ViewController { state: memberState, muteState: memberMuteState, canManageCall: self.callState?.canManageCall ?? false, - volume: member.volume, - raiseHandStatus: member.raiseHandRating != nil + volume: member.volume ))) index += 1 } @@ -2792,8 +2788,7 @@ public final class VoiceChatController: ViewController { state: .invited, muteState: nil, canManageCall: false, - volume: nil, - raiseHandStatus: false + volume: nil ))) index += 1 } From 4a7d5ccb678515214af1a6d8f2916f1ed43f5ed3 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 7 Mar 2021 09:32:20 +0400 Subject: [PATCH 2/2] Keep navigation stack when navigating to message in chat from shared media --- .../Sources/PeerInfo/PeerInfoScreen.swift | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 19e3a8db77..c2e85a2ea9 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -1724,7 +1724,27 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD items.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { c, _ in c.dismiss(completion: { if let strongSelf = self, let navigationController = strongSelf.controller?.navigationController as? NavigationController { - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(strongSelf.peerId), subject: .message(id: message.id, highlight: true))) + let currentPeerId = strongSelf.peerId + strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(currentPeerId), subject: .message(id: message.id, highlight: true), keepStack: .always, useExisting: false, purposefulAction: { + var viewControllers = navigationController.viewControllers + var indexesToRemove = Set() + var keptCurrentChatController = false + var index: Int = viewControllers.count - 1 + for controller in viewControllers.reversed() { + if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation { + if peerId == currentPeerId && !keptCurrentChatController { + keptCurrentChatController = true + } else { + indexesToRemove.insert(index) + } + } else if controller is PeerInfoScreen { + indexesToRemove.insert(index) + } + index -= 1 + } + viewControllers.remove(atOffsets: IndexSet(indexesToRemove)) + navigationController.setViewControllers(viewControllers, animated: false) + })) } }) }))) @@ -1844,7 +1864,27 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD items.append(.action(ContextMenuActionItem(text: strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { c, f in c.dismiss(completion: { if let strongSelf = self, let navigationController = strongSelf.controller?.navigationController as? NavigationController { - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(strongSelf.peerId), subject: .message(id: message.id, highlight: true))) + let currentPeerId = strongSelf.peerId + strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(currentPeerId), subject: .message(id: message.id, highlight: true), keepStack: .always, useExisting: false, purposefulAction: { + var viewControllers = navigationController.viewControllers + var indexesToRemove = Set() + var keptCurrentChatController = false + var index: Int = viewControllers.count - 1 + for controller in viewControllers.reversed() { + if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation { + if peerId == currentPeerId && !keptCurrentChatController { + keptCurrentChatController = true + } else { + indexesToRemove.insert(index) + } + } else if controller is PeerInfoScreen { + indexesToRemove.insert(index) + } + index -= 1 + } + viewControllers.remove(atOffsets: IndexSet(indexesToRemove)) + navigationController.setViewControllers(viewControllers, animated: false) + })) } }) }))) @@ -3702,11 +3742,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD guard let strongSelf = self else { return } - if false, let currentPeerId = currentPeerId { - if let navigationController = (strongSelf.controller?.navigationController as? NavigationController) { - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(currentPeerId))) - } - } else if let controller = strongSelf.controller { + if let controller = strongSelf.controller { let displayTitle = peer?.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder) ?? "" controller.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.UserInfo_StartSecretChatConfirmation(displayTitle).0, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.UserInfo_StartSecretChatStart, action: { guard let strongSelf = self else {