From a82110eb3a3bd04157aa5a9c85158da46e71c171 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Wed, 9 Nov 2022 22:17:59 +0400 Subject: [PATCH] Topic impovements --- .../ChatListUI/Sources/ChatContextMenus.swift | 21 ++++----- .../Sources/UnreadMessageCountsView.swift | 43 ++++++++++++++----- submodules/Postbox/Sources/Views.swift | 10 ++--- .../TelegramEngine/Data/MessagesData.swift | 2 +- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index 37988cf4f6..1f4bf1d278 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -312,19 +312,16 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch } } - if case let .channel(channel) = peer, channel.flags.contains(.isForum) { + if isUnread { + items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsRead, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsRead"), color: theme.contextMenu.primaryColor) }, action: { _, f in + let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start() + f(.default) + }))) } else { - if isUnread { - items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsRead, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsRead"), color: theme.contextMenu.primaryColor) }, action: { _, f in - let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start() - f(.default) - }))) - } else { - items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsUnread, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsUnread"), color: theme.contextMenu.primaryColor) }, action: { _, f in - let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start() - f(.default) - }))) - } + items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsUnread, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsUnread"), color: theme.contextMenu.primaryColor) }, action: { _, f in + let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start() + f(.default) + }))) } let archiveEnabled = !isSavedMessages && peerId != PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(777000)) && peerId == context.account.peerId diff --git a/submodules/Postbox/Sources/UnreadMessageCountsView.swift b/submodules/Postbox/Sources/UnreadMessageCountsView.swift index aabb2070dd..9ec6c8c036 100644 --- a/submodules/Postbox/Sources/UnreadMessageCountsView.swift +++ b/submodules/Postbox/Sources/UnreadMessageCountsView.swift @@ -67,7 +67,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView { if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) { var count: Int32 = 0 if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { - count = summary.effectiveUnreadCount + count = summary.totalUnreadCount } return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))])) } else { @@ -117,7 +117,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView { if transaction.updatedPeerThreadsSummaries.contains(peerId) { var count: Int32 = 0 if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { - count = summary.effectiveUnreadCount + count = summary.totalUnreadCount } self.entries[i] = .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))])) updated = true @@ -146,7 +146,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView { if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) { var count: Int32 = 0 if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { - count = summary.effectiveUnreadCount + count = summary.totalUnreadCount } return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))])) } else { @@ -212,21 +212,32 @@ public final class UnreadMessageCountsView: PostboxView { final class MutableCombinedReadStateView: MutablePostboxView { private let peerId: PeerId + private let handleThreads: Bool fileprivate var state: CombinedPeerReadState? - init(postbox: PostboxImpl, peerId: PeerId) { + init(postbox: PostboxImpl, peerId: PeerId, handleThreads: Bool) { self.peerId = peerId - self.state = postbox.readStateTable.getCombinedState(peerId) + self.handleThreads = handleThreads + + let _ = self.refreshDueToExternalTransaction(postbox: postbox) } func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false - if transaction.alteredInitialPeerCombinedReadStates[self.peerId] != nil { - let state = postbox.readStateTable.getCombinedState(peerId) - if state != self.state { - self.state = state - updated = true + if transaction.alteredInitialPeerCombinedReadStates[self.peerId] != nil || transaction.updatedPeerThreadCombinedStates.contains(self.peerId) { + if self.handleThreads, let peer = postbox.peerTable.get(self.peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) { + var count: Int32 = 0 + if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { + count = summary.totalUnreadCount + } + self.state = CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]) + } else { + let state = postbox.readStateTable.getCombinedState(peerId) + if state != self.state { + self.state = state + updated = true + } } } @@ -234,7 +245,17 @@ final class MutableCombinedReadStateView: MutablePostboxView { } func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool { - let state = postbox.readStateTable.getCombinedState(self.peerId) + let state: CombinedPeerReadState? + if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) { + var count: Int32 = 0 + if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { + count = summary.totalUnreadCount + } + state = CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]) + } else { + state = postbox.readStateTable.getCombinedState(peerId) + } + if state != self.state { self.state = state return true diff --git a/submodules/Postbox/Sources/Views.swift b/submodules/Postbox/Sources/Views.swift index b72a9f2833..7a1957c929 100644 --- a/submodules/Postbox/Sources/Views.swift +++ b/submodules/Postbox/Sources/Views.swift @@ -15,7 +15,7 @@ public enum PostboxViewKey: Hashable { case historyTagSummaryView(tag: MessageTags, peerId: PeerId, threadId: Int64?, namespace: MessageId.Namespace) case cachedPeerData(peerId: PeerId) case unreadCounts(items: [UnreadMessageCountsItem]) - case combinedReadState(peerId: PeerId) + case combinedReadState(peerId: PeerId, handleThreads: Bool) case peerNotificationSettings(peerIds: Set) case pendingPeerNotificationSettings case messageOfInterestHole(location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int) @@ -221,8 +221,8 @@ public enum PostboxViewKey: Hashable { } else { return false } - case let .combinedReadState(peerId): - if case .combinedReadState(peerId) = rhs { + case let .combinedReadState(peerId, handleThreads): + if case .combinedReadState(peerId, handleThreads) = rhs { return true } else { return false @@ -405,8 +405,8 @@ func postboxViewForKey(postbox: PostboxImpl, key: PostboxViewKey) -> MutablePost return MutableCachedPeerDataView(postbox: postbox, peerId: peerId) case let .unreadCounts(items): return MutableUnreadMessageCountsView(postbox: postbox, items: items) - case let .combinedReadState(peerId): - return MutableCombinedReadStateView(postbox: postbox, peerId: peerId) + case let .combinedReadState(peerId, handleThreads): + return MutableCombinedReadStateView(postbox: postbox, peerId: peerId, handleThreads: handleThreads) case let .peerNotificationSettings(peerIds): return MutablePeerNotificationSettingsView(postbox: postbox, peerIds: peerIds) case .pendingPeerNotificationSettings: diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Data/MessagesData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Data/MessagesData.swift index a8efaaf490..774ec5cb84 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Data/MessagesData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Data/MessagesData.swift @@ -169,7 +169,7 @@ public extension TelegramEngine.EngineData.Item { } var key: PostboxViewKey { - return .combinedReadState(peerId: self.id) + return .combinedReadState(peerId: self.id, handleThreads: true) } public init(id: EnginePeer.Id) {