Initial implementation of channel overscroll navigation

This commit is contained in:
Ali
2021-07-27 17:36:35 +02:00
parent 6cec47b5f7
commit e85f3884d4
27 changed files with 2940 additions and 2 deletions

View File

@@ -478,5 +478,35 @@ public extension TelegramEngine {
public func updatePeerDescription(peerId: PeerId, description: String?) -> Signal<Void, UpdatePeerDescriptionError> {
return _internal_updatePeerDescription(account: self.account, peerId: peerId, description: description)
}
public func getNextUnreadChannel(peerId: PeerId) -> Signal<EnginePeer?, NoError> {
return self.account.postbox.transaction { transaction -> EnginePeer? in
var peers: [RenderedPeer] = []
peers.append(contentsOf: transaction.getTopChatListEntries(groupId: .root, count: 100))
peers.append(contentsOf: transaction.getTopChatListEntries(groupId: Namespaces.PeerGroup.archive, count: 100))
var results: [(EnginePeer, Int32)] = []
for peer in peers {
guard let channel = peer.chatMainPeer as? TelegramChannel, case .broadcast = channel.info else {
continue
}
if channel.id == peerId {
continue
}
guard let readState = transaction.getCombinedPeerReadState(channel.id), readState.count != 0 else {
continue
}
guard let topMessageIndex = transaction.getTopPeerMessageIndex(peerId: channel.id) else {
continue
}
results.append((EnginePeer(channel), topMessageIndex.timestamp))
}
results.sort(by: { $0.1 > $1.1 })
return results.first?.0
}
}
}
}