Animation updates

This commit is contained in:
Ali
2021-08-10 21:18:55 +02:00
parent e170f2fe5a
commit 904b048a34
46 changed files with 961 additions and 596 deletions

View File

@@ -25,6 +25,13 @@ public final class OpaqueChatInterfaceState {
}
public extension TelegramEngine {
enum NextUnreadChannelLocation: Equatable {
case same
case archived
case unarchived
case folder(id: Int32, title: String)
}
final class Peers {
private let account: Account
@@ -495,40 +502,90 @@ public extension TelegramEngine {
return _internal_updatePeerDescription(account: self.account, peerId: peerId, description: description)
}
public func getNextUnreadChannel(peerId: PeerId, filter: ChatListFilterPredicate?) -> Signal<(peer: EnginePeer, unreadCount: Int)?, NoError> {
return self.account.postbox.transaction { transaction -> (peer: EnginePeer, unreadCount: Int)? in
var results: [(EnginePeer, Int32)] = []
var peerIds: [PeerId] = []
peerIds.append(contentsOf: transaction.getUnreadChatListPeerIds(groupId: .root, filterPredicate: filter))
peerIds.append(contentsOf: transaction.getUnreadChatListPeerIds(groupId: Namespaces.PeerGroup.archive, filterPredicate: filter))
for listId in peerIds {
guard let peer = transaction.getPeer(listId) else {
continue
}
guard let channel = peer 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
public func getNextUnreadChannel(peerId: PeerId, chatListFilterId: Int32?, getFilterPredicate: @escaping (ChatListFilterData) -> ChatListFilterPredicate) -> Signal<(peer: EnginePeer, unreadCount: Int, location: NextUnreadChannelLocation)?, NoError> {
return self.account.postbox.transaction { transaction -> (peer: EnginePeer, unreadCount: Int, location: NextUnreadChannelLocation)? in
func getForFilter(predicate: ChatListFilterPredicate?, isArchived: Bool) -> (peer: EnginePeer, unreadCount: Int)? {
var peerIds: [PeerId] = []
if predicate != nil {
peerIds.append(contentsOf: transaction.getUnreadChatListPeerIds(groupId: .root, filterPredicate: predicate))
peerIds.append(contentsOf: transaction.getUnreadChatListPeerIds(groupId: Namespaces.PeerGroup.archive, filterPredicate: predicate))
} else {
if isArchived {
peerIds.append(contentsOf: transaction.getUnreadChatListPeerIds(groupId: Namespaces.PeerGroup.archive, filterPredicate: nil))
} else {
peerIds.append(contentsOf: transaction.getUnreadChatListPeerIds(groupId: .root, filterPredicate: nil))
}
}
results.append((EnginePeer(channel), topMessageIndex.timestamp))
var results: [(EnginePeer, Int32)] = []
for listId in peerIds {
guard let peer = transaction.getPeer(listId) else {
continue
}
guard let channel = peer 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 })
if let peer = results.first?.0 {
let unreadCount: Int32 = transaction.getCombinedPeerReadState(peer.id)?.count ?? 0
return (peer: peer, unreadCount: Int(unreadCount))
} else {
return nil
}
}
results.sort(by: { $0.1 > $1.1 })
guard let peerGroupId = transaction.getPeerChatListIndex(peerId)?.0 else {
return nil
}
if let peer = results.first?.0 {
let unreadCount: Int32 = transaction.getCombinedPeerReadState(peer.id)?.count ?? 0
return (peer: peer, unreadCount: Int(unreadCount))
if let filterId = chatListFilterId {
let filters = _internal_currentChatListFilters(transaction: transaction)
guard let index = filters.firstIndex(where: { $0.id == filterId }) else {
return nil
}
var sortedFilters: [ChatListFilter] = []
sortedFilters.append(contentsOf: filters[index...])
sortedFilters.append(contentsOf: filters[0 ..< index])
for i in 0 ..< sortedFilters.count {
if let value = getForFilter(predicate: getFilterPredicate(sortedFilters[i].data), isArchived: false) {
return (peer: value.peer, unreadCount: value.unreadCount, location: i == 0 ? .same : .folder(id: sortedFilters[i].id, title: sortedFilters[i].title))
}
}
return nil
} else {
let folderOrder: [(PeerGroupId, NextUnreadChannelLocation)]
if peerGroupId == .root {
folderOrder = [
(.root, .same),
(Namespaces.PeerGroup.archive, .archived),
]
} else {
folderOrder = [
(Namespaces.PeerGroup.archive, .same),
(.root, .unarchived),
]
}
for (groupId, location) in folderOrder {
if let value = getForFilter(predicate: nil, isArchived: groupId != .root) {
return (peer: value.peer, unreadCount: value.unreadCount, location: location)
}
}
return nil
}
}