mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Animation updates
This commit is contained in:
@@ -860,6 +860,11 @@ func _internal_currentChatListFilters(postbox: Postbox) -> Signal<[ChatListFilte
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_currentChatListFilters(transaction: Transaction) -> [ChatListFilter] {
|
||||
let settings = transaction.getPreferencesEntry(key: PreferencesKeys.chatListFilters) as? ChatListFiltersState ?? ChatListFiltersState.default
|
||||
return settings.filters
|
||||
}
|
||||
|
||||
func updateChatListFiltersState(transaction: Transaction, _ f: (ChatListFiltersState) -> ChatListFiltersState) -> ChatListFiltersState {
|
||||
var result: ChatListFiltersState?
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.chatListFilters, { entry in
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user