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)
|
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)? {
|
public func getPeerChatListIndex(_ peerId: PeerId) -> (PeerGroupId, ChatListIndex)? {
|
||||||
assert(!self.disposed)
|
assert(!self.disposed)
|
||||||
return self.postbox?.chatListTable.getPeerChatListIndex(peerId: peerId)
|
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 {
|
fileprivate func getPeerChatListInclusion(_ id: PeerId) -> PeerChatListInclusion {
|
||||||
if let inclusion = self.currentUpdatedChatListInclusions[id] {
|
if let inclusion = self.currentUpdatedChatListInclusions[id] {
|
||||||
return inclusion
|
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) {
|
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 {
|
if peerId.namespace == Namespaces.Peer.SecretChat {
|
||||||
namespace = Namespaces.Message.SecretIncoming
|
principalNamespace = Namespaces.Message.SecretIncoming
|
||||||
} else {
|
} else {
|
||||||
namespace = Namespaces.Message.Cloud
|
principalNamespace = Namespaces.Message.Cloud
|
||||||
}
|
}
|
||||||
|
var hasUnread = false
|
||||||
if let states = transaction.getPeerReadStates(peerId) {
|
if let states = transaction.getPeerReadStates(peerId) {
|
||||||
for i in 0 ..< states.count {
|
for state in states {
|
||||||
if states[i].0 == namespace {
|
if state.1.isUnread {
|
||||||
if states[i].1.isUnread {
|
hasUnread = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasUnread {
|
||||||
if setToValue == nil || !(setToValue!) {
|
if setToValue == nil || !(setToValue!) {
|
||||||
if let index = transaction.getTopPeerMessageIndex(peerId: peerId, namespace: namespace) {
|
if let index = transaction.getTopPeerMessageIndex(peerId: peerId) {
|
||||||
let _ = transaction.applyInteractiveReadMaxIndex(index)
|
let _ = transaction.applyInteractiveReadMaxIndex(index)
|
||||||
} else {
|
} 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)
|
viewTracker.updateMarkAllMentionsSeen(peerId: peerId)
|
||||||
}
|
}
|
||||||
} else if namespace == Namespaces.Message.Cloud || namespace == Namespaces.Message.SecretIncoming {
|
} else {
|
||||||
if setToValue == nil || setToValue! {
|
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