From dbaef794d47a87f3df9b62c8155eda2dd32ed216 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 12 Mar 2021 19:11:30 +0400 Subject: [PATCH 1/5] Cleanup --- .../Sources/PresentationGroupCall.swift | 5 +++-- submodules/TelegramCore/Sources/GroupCalls.swift | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift index 10a833b9ba..98e2333fbb 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift @@ -1309,10 +1309,12 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { return rawAdminIds } |> distinctUntilChanged + + let myPeerId = self.joinAsPeerId var initialState = initialState if let participantsContext = self.participantsContext, let immediateState = participantsContext.immediateState { - initialState.mergeActivity(from: immediateState) + initialState.mergeActivity(from: immediateState, myPeerId: myPeerId, previousMyPeerId: self.ignorePreviousJoinAsPeerId?.0) } let participantsContext = GroupCallParticipantsContext( @@ -1325,7 +1327,6 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { ) self.temporaryParticipantsContext = nil self.participantsContext = participantsContext - let myPeerId = self.joinAsPeerId let myPeer = self.accountContext.account.postbox.transaction { transaction -> (Peer, CachedPeerData?)? in if let peer = transaction.getPeer(myPeerId) { return (peer, transaction.getPeerCachedData(peerId: myPeerId)) diff --git a/submodules/TelegramCore/Sources/GroupCalls.swift b/submodules/TelegramCore/Sources/GroupCalls.swift index 49bf98c06b..8a34f135c3 100644 --- a/submodules/TelegramCore/Sources/GroupCalls.swift +++ b/submodules/TelegramCore/Sources/GroupCalls.swift @@ -452,7 +452,7 @@ public func joinGroupCall(account: Account, peerId: PeerId, joinAs: PeerId?, cal return .fail(.generic) } - var apiUsers: [Api.User] = [] + let apiUsers: [Api.User] = [] state.adminIds = Set(peerAdminIds) @@ -755,7 +755,7 @@ public final class GroupCallParticipantsContext { public var totalCount: Int public var version: Int32 - public mutating func mergeActivity(from other: State) { + public mutating func mergeActivity(from other: State, myPeerId: PeerId, previousMyPeerId: PeerId?) { var indexMap: [PeerId: Int] = [:] for i in 0 ..< other.participants.count { indexMap[other.participants[i].peer.id] = i @@ -764,6 +764,9 @@ public final class GroupCallParticipantsContext { for i in 0 ..< self.participants.count { if let index = indexMap[self.participants[i].peer.id] { self.participants[i].mergeActivity(from: other.participants[index]) + if self.participants[i].peer.id == myPeerId || self.participants[i].peer.id == previousMyPeerId { + self.participants[i].joinTimestamp = other.participants[index].joinTimestamp + } } } @@ -1292,9 +1295,11 @@ public final class GroupCallParticipantsContext { assertionFailure() continue } + var previousJoinTimestamp: Int32? var previousActivityTimestamp: Double? var previousActivityRank: Int? if let index = updatedParticipants.firstIndex(where: { $0.peer.id == participantUpdate.peerId }) { + previousJoinTimestamp = updatedParticipants[index].joinTimestamp previousActivityTimestamp = updatedParticipants[index].activityTimestamp previousActivityRank = updatedParticipants[index].activityRank updatedParticipants.remove(at: index) @@ -1302,7 +1307,7 @@ public final class GroupCallParticipantsContext { updatedTotalCount += 1 strongSelf.memberEventsPipe.putNext(MemberEvent(peerId: participantUpdate.peerId, joined: true)) } - + var activityTimestamp: Double? if let previousActivityTimestamp = previousActivityTimestamp, let updatedActivityTimestamp = participantUpdate.activityTimestamp { activityTimestamp = max(updatedActivityTimestamp, previousActivityTimestamp) @@ -1314,7 +1319,7 @@ public final class GroupCallParticipantsContext { peer: peer, ssrc: participantUpdate.ssrc, jsonParams: participantUpdate.jsonParams, - joinTimestamp: participantUpdate.joinTimestamp, + joinTimestamp: previousJoinTimestamp ?? participantUpdate.joinTimestamp, raiseHandRating: participantUpdate.raiseHandRating, hasRaiseHand: participantUpdate.raiseHandRating != nil, activityTimestamp: activityTimestamp, @@ -1773,9 +1778,8 @@ public func groupCallDisplayAsAvailablePeers(network: Network, postbox: Postbox, return network.request(Api.functions.phone.getGroupCallJoinAs(peer: inputPeer)) |> retryRequest |> mapToSignal { result in - var peers:[Peer] switch result { - case let .joinAsPeers(peers, chats, users): + case let .joinAsPeers(_, chats, _): var subscribers: [PeerId: Int32] = [:] let peers = chats.compactMap(parseTelegramGroupOrChannel) for chat in chats { From c849d2f88ae08112979e7594039bf5789ca080c9 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 12 Mar 2021 19:55:14 +0400 Subject: [PATCH 2/5] Display legacy group voice chats on call tab --- submodules/CallListUI/Sources/CallListControllerNode.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/submodules/CallListUI/Sources/CallListControllerNode.swift b/submodules/CallListUI/Sources/CallListControllerNode.swift index 3eb2d20c59..1da7ab001d 100644 --- a/submodules/CallListUI/Sources/CallListControllerNode.swift +++ b/submodules/CallListUI/Sources/CallListControllerNode.swift @@ -426,6 +426,8 @@ final class CallListControllerNode: ASDisplayNode { case let .MessageEntry(_, _, _, _, _, renderedPeer, _, _, _, _): if let channel = renderedPeer.peer as? TelegramChannel, channel.flags.contains(.hasActiveVoiceChat) { result.append(channel) + } else if let group = renderedPeer.peer as? TelegramGroup, group.flags.contains(.hasActiveVoiceChat) { + result.append(group) } default: break From 5c53c9964ee471ccf6a2aeac3ddbdef7e5a5f92b Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 12 Mar 2021 19:55:31 +0400 Subject: [PATCH 3/5] Update status bar style with animation --- submodules/TelegramCallsUI/Sources/VoiceChatController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 1e49bfeecd..5052e0139a 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -2340,8 +2340,8 @@ public final class VoiceChatController: ViewController { return } self.isFullscreen = isFullscreen - - self.controller?.statusBar.statusBarStyle = isFullscreen ? .White : .Ignore + + self.controller?.statusBar.updateStatusBarStyle(isFullscreen ? .White : .Ignore, animated: true) var size = layout.size if case .regular = layout.metrics.widthClass { From 1a8e96ccc799c0cc007d790d108b2e7bec186477 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 12 Mar 2021 20:43:51 +0400 Subject: [PATCH 4/5] Allow scrolling in context menus --- submodules/ContextUI/Sources/ContextController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/submodules/ContextUI/Sources/ContextController.swift b/submodules/ContextUI/Sources/ContextController.swift index a338e004bb..cf9037222a 100644 --- a/submodules/ContextUI/Sources/ContextController.swift +++ b/submodules/ContextUI/Sources/ContextController.swift @@ -1267,6 +1267,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } var contentHeight = max(layout.size.height, max(layout.size.height, originalActionsFrame.maxY + actionsBottomInset) - originalContentFrame.minY + contentTopInset) + contentHeight = max(contentHeight, actionsSize.height + originalActionsFrame.minY + actionsBottomInset) var overflowOffset: CGFloat var contentContainerFrame: CGRect From 2d1c7295adb93b20b951b8e03a6b9ff39ab647e2 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 12 Mar 2021 20:44:18 +0400 Subject: [PATCH 5/5] Check that chats exist before displaying in-app notifications --- .../Sources/ApplicationContext.swift | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/submodules/TelegramUI/Sources/ApplicationContext.swift b/submodules/TelegramUI/Sources/ApplicationContext.swift index d478d1151c..cc91f7e4a6 100644 --- a/submodules/TelegramUI/Sources/ApplicationContext.swift +++ b/submodules/TelegramUI/Sources/ApplicationContext.swift @@ -257,9 +257,28 @@ final class AuthorizedApplicationContext { } } })) - + + let postbox = context.account.postbox self.notificationMessagesDisposable.set((context.account.stateManager.notificationMessages + |> mapToSignal { messageList -> Signal<[([Message], PeerGroupId, Bool)], NoError> in + return postbox.transaction { transaction -> [([Message], PeerGroupId, Bool)] in + return messageList.filter { item in + guard let message = item.0.first else { + return false + } + let inclusion = transaction.getPeerChatListInclusion(message.id.peerId) + if case .notIncluded = inclusion { + return false + } + return true + } + } + } |> deliverOn(Queue.mainQueue())).start(next: { [weak self] messageList in + if messageList.isEmpty { + return + } + if let strongSelf = self, let (messages, _, notify) = messageList.last, let firstMessage = messages.first { if UIApplication.shared.applicationState == .active { var chatIsVisible = false