diff --git a/submodules/Display/Source/Navigation/NavigationController.swift b/submodules/Display/Source/Navigation/NavigationController.swift index 570deb5dda..a6c17d41c3 100644 --- a/submodules/Display/Source/Navigation/NavigationController.swift +++ b/submodules/Display/Source/Navigation/NavigationController.swift @@ -1323,6 +1323,30 @@ open class NavigationController: UINavigationController, ContainableController, } open override func setViewControllers(_ viewControllers: [UIViewController], animated: Bool) { + for i in 0 ..< viewControllers.count { + guard let controller = viewControllers[i] as? ViewController else { + continue + } + if self.viewControllers.contains(where: { $0 === controller }) { + continue + } + if let customNavigationData = controller.customNavigationData { + var found = false + for previousIndex in (0 ..< self.viewControllers.count).reversed() { + let previousController = self.viewControllers[previousIndex] + + if let previousController = previousController as? ViewController, let previousCustomNavigationDataSummary = previousController.customNavigationDataSummary { + controller.customNavigationDataSummary = customNavigationData.combine(summary: previousCustomNavigationDataSummary) + found = true + break + } + } + if !found { + controller.customNavigationDataSummary = customNavigationData.combine(summary: nil) + } + } + } + self._viewControllers = viewControllers.map { controller in let controller = controller as! ViewController controller.navigation_setNavigationController(self) diff --git a/submodules/Display/Source/ViewController.swift b/submodules/Display/Source/ViewController.swift index d5f8844fa3..80de7e8eef 100644 --- a/submodules/Display/Source/ViewController.swift +++ b/submodules/Display/Source/ViewController.swift @@ -73,6 +73,13 @@ public enum TabBarItemContextActionType { case whenActive } +public protocol CustomViewControllerNavigationData: AnyObject { + func combine(summary: CustomViewControllerNavigationDataSummary?) -> CustomViewControllerNavigationDataSummary? +} + +public protocol CustomViewControllerNavigationDataSummary: AnyObject { +} + @objc open class ViewController: UIViewController, ContainableController { public struct NavigationLayout { public var navigationFrame: CGRect @@ -274,6 +281,13 @@ public enum TabBarItemContextActionType { } } + open var customNavigationData: CustomViewControllerNavigationData? { + get { + return nil + } + } + open var customNavigationDataSummary: CustomViewControllerNavigationDataSummary? + public internal(set) var isInFocus: Bool = false { didSet { if self.isInFocus != oldValue { diff --git a/submodules/TelegramCore/Sources/State/AccountViewTracker.swift b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift index 04ded46aa1..0d103f222a 100644 --- a/submodules/TelegramCore/Sources/State/AccountViewTracker.swift +++ b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift @@ -1868,9 +1868,9 @@ public final class AccountViewTracker { } } var reactionCount: Int32 = 0 - if let view = views.views[pendingReactionsKey] as? PendingMessageActionsSummaryView { + /*if let view = views.views[pendingReactionsKey] as? PendingMessageActionsSummaryView { reactionCount -= view.count - } + }*/ if let view = views.views[summaryReactionsKey] as? MessageHistoryTagSummaryView { if let unseenCount = view.count { reactionCount += unseenCount diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/ChatList.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ChatList.swift index 4278c8dea9..c3fb924f16 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/ChatList.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ChatList.swift @@ -231,7 +231,7 @@ extension EngineChatList.Item { tag: .unseenReaction, actionType: PendingMessageActionType.readReaction )] { - hasUnseenReactions = (info.tagSummaryCount ?? 0) > (info.actionsSummaryCount ?? 0) + hasUnseenReactions = (info.tagSummaryCount ?? 0) != 0// > (info.actionsSummaryCount ?? 0) } self.init( diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift index 350389d9d9..9dc6ef1aef 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift @@ -15,6 +15,9 @@ func _internal_earliestUnseenPersonalMentionMessage(account: Account, peerId: Pe if view.0.isLoading { return .single(.loading) } + if case .FillHole = view.1 { + return _internal_earliestUnseenPersonalMentionMessage(account: account, peerId: peerId) + } if let message = view.0.entries.first?.message { if peerId.namespace == Namespaces.Peer.CloudChannel { var invalidatedPts: Int32? @@ -79,6 +82,9 @@ func _internal_earliestUnseenPersonalReactionMessage(account: Account, peerId: P if view.0.isLoading { return .single(.loading) } + if case .FillHole = view.1 { + return _internal_earliestUnseenPersonalReactionMessage(account: account, peerId: peerId) + } if let message = view.0.entries.first?.message { if peerId.namespace == Namespaces.Peer.CloudChannel { var invalidatedPts: Int32? diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift index 02ee5088d6..18b97f36b6 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift @@ -7,6 +7,7 @@ func _internal_installInteractiveReadMessagesAction(postbox: Postbox, stateManag return postbox.installStoreMessageAction(peerId: peerId, { messages, transaction in var consumeMessageIds: [MessageId] = [] var readReactionIds: [MessageId] = [] + readReactionIds.removeAll() var readMessageIndexByNamespace: [MessageId.Namespace: MessageIndex] = [:] @@ -32,7 +33,7 @@ func _internal_installInteractiveReadMessagesAction(postbox: Postbox, stateManag consumeMessageIds.append(id) } if hasUnseenReactions { - readReactionIds.append(id) + //readReactionIds.append(id) } if !message.flags.intersection(.IsIncomingMask).isEmpty { @@ -56,6 +57,7 @@ func _internal_installInteractiveReadMessagesAction(postbox: Postbox, stateManag } } } + var tags = currentMessage.tags if readReactionIds.contains(id) { reactionsLoop: for j in 0 ..< attributes.count { if let attribute = attributes[j] as? ReactionsMessageAttribute { @@ -63,9 +65,8 @@ func _internal_installInteractiveReadMessagesAction(postbox: Postbox, stateManag break reactionsLoop } } + tags.remove(.unseenReaction) } - var tags = currentMessage.tags - tags.remove(.unseenReaction) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: currentMessage.forwardInfo.flatMap(StoreMessageForwardInfo.init), authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media)) }) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 421c530ac9..21ca2094a0 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -475,6 +475,16 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return self.chatLocation } + override public var customNavigationData: CustomViewControllerNavigationData? { + get { + if case let .peer(peerId) = self.chatLocation { + return ChatControllerNavigationData(peerId: peerId) + } else { + return nil + } + } + } + private var scheduledScrollToMessageId: (MessageId, Double?)? public var purposefulAction: (() -> Void)? @@ -8498,14 +8508,20 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }) } - if !self.chatNavigationStack.isEmpty { + var chatNavigationStack: [PeerId] = self.chatNavigationStack + if case let .peer(peerId) = self.chatLocation, let summary = self.customNavigationDataSummary as? ChatControllerNavigationDataSummary { + chatNavigationStack.removeAll() + chatNavigationStack = summary.peerIds.filter({ $0 != peerId }) + } + + if !chatNavigationStack.isEmpty { self.chatDisplayNode.navigationBar?.backButtonNode.isGestureEnabled = true self.chatDisplayNode.navigationBar?.backButtonNode.activated = { [weak self] gesture, _ in guard let strongSelf = self else { gesture.cancel() return } - let chatNavigationStack = strongSelf.chatNavigationStack + let _ = (strongSelf.context.account.postbox.transaction { transaction -> [Peer] in return chatNavigationStack.compactMap(transaction.getPeer) } @@ -8525,10 +8541,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } - let snapshotState = strongSelf.chatDisplayNode.prepareSnapshotState( + /*let snapshotState = strongSelf.chatDisplayNode.prepareSnapshotState( titleViewSnapshotState: strongSelf.chatTitleView?.prepareSnapshotState(), avatarSnapshotState: (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.prepareSnapshotState() - ) + )*/ let nextFolderId: Int32? = strongSelf.currentChatListFilter @@ -8537,8 +8553,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G updatedChatNavigationStack.removeSubrange(0 ..< (index + 1)) } - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peer.id), animated: false, chatListFilter: nextFolderId, chatNavigationStack: updatedChatNavigationStack, completion: { nextController in - (nextController as! ChatControllerImpl).animateFromPreviousController(snapshotState: snapshotState) + strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peer.id), animated: true, chatListFilter: nextFolderId, chatNavigationStack: updatedChatNavigationStack, completion: { nextController in + let _ = nextController + //(nextController as! ChatControllerImpl).animateFromPreviousController(snapshotState: snapshotState) })) }))) } @@ -14832,3 +14849,34 @@ func peerAllowedReactions(context: AccountContext, peerId: PeerId) -> Signal CustomViewControllerNavigationDataSummary? { + if let summary = summary as? ChatControllerNavigationDataSummary { + return summary.adding(peerId: self.peerId) + } else { + return ChatControllerNavigationDataSummary(peerIds: [self.peerId]) + } + } +} + +final class ChatControllerNavigationDataSummary: CustomViewControllerNavigationDataSummary { + let peerIds: [PeerId] + + init(peerIds: [PeerId]) { + self.peerIds = peerIds + } + + func adding(peerId: PeerId) -> ChatControllerNavigationDataSummary { + var peerIds = self.peerIds + peerIds.removeAll(where: { $0 == peerId }) + peerIds.insert(peerId, at: 0) + return ChatControllerNavigationDataSummary(peerIds: peerIds) + } +}