Topic impovements

This commit is contained in:
Ali 2022-11-09 22:17:59 +04:00
parent 8eb3d82257
commit a82110eb3a
4 changed files with 47 additions and 29 deletions

View File

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

View File

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

View File

@ -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<PeerId>)
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:

View File

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