mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Fix mark as read
This commit is contained in:
parent
897a76a0df
commit
a91b0bade5
@ -282,6 +282,11 @@ public final class Transaction {
|
||||
return self.postbox?.getTopPeerMessageIndex(peerId: peerId, namespace: namespace)
|
||||
}
|
||||
|
||||
public func getTopPeerMessageIndex(peerId: PeerId) -> MessageIndex? {
|
||||
assert(!self.disposed)
|
||||
return self.postbox?.getTopPeerMessageIndex(peerId: peerId)
|
||||
}
|
||||
|
||||
public func getPeerChatListIndex(_ peerId: PeerId) -> (PeerGroupId, ChatListIndex)? {
|
||||
assert(!self.disposed)
|
||||
return self.postbox?.chatListTable.getPeerChatListIndex(peerId: peerId)
|
||||
@ -1781,6 +1786,15 @@ public final class Postbox {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func getTopPeerMessageIndex(peerId: PeerId) -> MessageIndex? {
|
||||
var indices: [MessageIndex] = []
|
||||
for namespace in self.messageHistoryIndexTable.existingNamespaces(peerId: peerId) {
|
||||
if let index = self.messageHistoryTable.topIndexEntry(peerId: peerId, namespace: namespace) {
|
||||
indices.append(index)
|
||||
}
|
||||
}
|
||||
return indices.max()
|
||||
}
|
||||
fileprivate func getPeerChatListInclusion(_ id: PeerId) -> PeerChatListInclusion {
|
||||
if let inclusion = self.currentUpdatedChatListInclusions[id] {
|
||||
return inclusion
|
||||
|
||||
@ -123,30 +123,34 @@ public func togglePeerUnreadMarkInteractively(postbox: Postbox, viewTracker: Acc
|
||||
}
|
||||
|
||||
public func togglePeerUnreadMarkInteractively(transaction: Transaction, viewTracker: AccountViewTracker, peerId: PeerId, setToValue: Bool? = nil) {
|
||||
let namespace: MessageId.Namespace
|
||||
let principalNamespace: MessageId.Namespace
|
||||
if peerId.namespace == Namespaces.Peer.SecretChat {
|
||||
namespace = Namespaces.Message.SecretIncoming
|
||||
principalNamespace = Namespaces.Message.SecretIncoming
|
||||
} else {
|
||||
namespace = Namespaces.Message.Cloud
|
||||
principalNamespace = Namespaces.Message.Cloud
|
||||
}
|
||||
var hasUnread = false
|
||||
if let states = transaction.getPeerReadStates(peerId) {
|
||||
for i in 0 ..< states.count {
|
||||
if states[i].0 == namespace {
|
||||
if states[i].1.isUnread {
|
||||
for state in states {
|
||||
if state.1.isUnread {
|
||||
hasUnread = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if hasUnread {
|
||||
if setToValue == nil || !(setToValue!) {
|
||||
if let index = transaction.getTopPeerMessageIndex(peerId: peerId, namespace: namespace) {
|
||||
if let index = transaction.getTopPeerMessageIndex(peerId: peerId) {
|
||||
let _ = transaction.applyInteractiveReadMaxIndex(index)
|
||||
} else {
|
||||
transaction.applyMarkUnread(peerId: peerId, namespace: namespace, value: false, interactive: true)
|
||||
transaction.applyMarkUnread(peerId: peerId, namespace: principalNamespace, value: false, interactive: true)
|
||||
}
|
||||
viewTracker.updateMarkAllMentionsSeen(peerId: peerId)
|
||||
}
|
||||
} else if namespace == Namespaces.Message.Cloud || namespace == Namespaces.Message.SecretIncoming {
|
||||
} else {
|
||||
if setToValue == nil || setToValue! {
|
||||
transaction.applyMarkUnread(peerId: peerId, namespace: namespace, value: true, interactive: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
transaction.applyMarkUnread(peerId: peerId, namespace: principalNamespace, value: true, interactive: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user