Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2022-11-09 23:18:44 +04:00
commit c0248b4ac5
4 changed files with 47 additions and 29 deletions

View File

@ -312,8 +312,6 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
} }
} }
if case let .channel(channel) = peer, channel.flags.contains(.isForum) {
} else {
if isUnread { 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 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() let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start()
@ -325,7 +323,6 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
f(.default) f(.default)
}))) })))
} }
}
let archiveEnabled = !isSavedMessages && peerId != PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(777000)) && peerId == context.account.peerId let archiveEnabled = !isSavedMessages && peerId != PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(777000)) && peerId == context.account.peerId
if let group = peerGroup { if let group = peerGroup {

View File

@ -67,7 +67,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView {
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) { if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
var count: Int32 = 0 var count: Int32 = 0
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { 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))])) return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
} else { } else {
@ -117,7 +117,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView {
if transaction.updatedPeerThreadsSummaries.contains(peerId) { if transaction.updatedPeerThreadsSummaries.contains(peerId) {
var count: Int32 = 0 var count: Int32 = 0
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { 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))])) self.entries[i] = .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
updated = true updated = true
@ -146,7 +146,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView {
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) { if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
var count: Int32 = 0 var count: Int32 = 0
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) { 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))])) return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
} else { } else {
@ -212,29 +212,50 @@ public final class UnreadMessageCountsView: PostboxView {
final class MutableCombinedReadStateView: MutablePostboxView { final class MutableCombinedReadStateView: MutablePostboxView {
private let peerId: PeerId private let peerId: PeerId
private let handleThreads: Bool
fileprivate var state: CombinedPeerReadState? fileprivate var state: CombinedPeerReadState?
init(postbox: PostboxImpl, peerId: PeerId) { init(postbox: PostboxImpl, peerId: PeerId, handleThreads: Bool) {
self.peerId = peerId self.peerId = peerId
self.state = postbox.readStateTable.getCombinedState(peerId) self.handleThreads = handleThreads
let _ = self.refreshDueToExternalTransaction(postbox: postbox)
} }
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
var updated = false var updated = false
if transaction.alteredInitialPeerCombinedReadStates[self.peerId] != nil { 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) let state = postbox.readStateTable.getCombinedState(peerId)
if state != self.state { if state != self.state {
self.state = state self.state = state
updated = true updated = true
} }
} }
}
return updated return updated
} }
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool { 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 { if state != self.state {
self.state = state self.state = state
return true return true

View File

@ -15,7 +15,7 @@ public enum PostboxViewKey: Hashable {
case historyTagSummaryView(tag: MessageTags, peerId: PeerId, threadId: Int64?, namespace: MessageId.Namespace) case historyTagSummaryView(tag: MessageTags, peerId: PeerId, threadId: Int64?, namespace: MessageId.Namespace)
case cachedPeerData(peerId: PeerId) case cachedPeerData(peerId: PeerId)
case unreadCounts(items: [UnreadMessageCountsItem]) case unreadCounts(items: [UnreadMessageCountsItem])
case combinedReadState(peerId: PeerId) case combinedReadState(peerId: PeerId, handleThreads: Bool)
case peerNotificationSettings(peerIds: Set<PeerId>) case peerNotificationSettings(peerIds: Set<PeerId>)
case pendingPeerNotificationSettings case pendingPeerNotificationSettings
case messageOfInterestHole(location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int) case messageOfInterestHole(location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int)
@ -221,8 +221,8 @@ public enum PostboxViewKey: Hashable {
} else { } else {
return false return false
} }
case let .combinedReadState(peerId): case let .combinedReadState(peerId, handleThreads):
if case .combinedReadState(peerId) = rhs { if case .combinedReadState(peerId, handleThreads) = rhs {
return true return true
} else { } else {
return false return false
@ -405,8 +405,8 @@ func postboxViewForKey(postbox: PostboxImpl, key: PostboxViewKey) -> MutablePost
return MutableCachedPeerDataView(postbox: postbox, peerId: peerId) return MutableCachedPeerDataView(postbox: postbox, peerId: peerId)
case let .unreadCounts(items): case let .unreadCounts(items):
return MutableUnreadMessageCountsView(postbox: postbox, items: items) return MutableUnreadMessageCountsView(postbox: postbox, items: items)
case let .combinedReadState(peerId): case let .combinedReadState(peerId, handleThreads):
return MutableCombinedReadStateView(postbox: postbox, peerId: peerId) return MutableCombinedReadStateView(postbox: postbox, peerId: peerId, handleThreads: handleThreads)
case let .peerNotificationSettings(peerIds): case let .peerNotificationSettings(peerIds):
return MutablePeerNotificationSettingsView(postbox: postbox, peerIds: peerIds) return MutablePeerNotificationSettingsView(postbox: postbox, peerIds: peerIds)
case .pendingPeerNotificationSettings: case .pendingPeerNotificationSettings:

View File

@ -169,7 +169,7 @@ public extension TelegramEngine.EngineData.Item {
} }
var key: PostboxViewKey { var key: PostboxViewKey {
return .combinedReadState(peerId: self.id) return .combinedReadState(peerId: self.id, handleThreads: true)
} }
public init(id: EnginePeer.Id) { public init(id: EnginePeer.Id) {