Folder improvements

This commit is contained in:
Ali
2020-03-20 13:01:09 +04:00
parent 46ea78b6c3
commit ceccb98af7
16 changed files with 152 additions and 63 deletions

View File

@@ -15,23 +15,36 @@ struct ChatListSelectionOptions: Equatable {
let delete: Bool
}
func chatListSelectionOptions(postbox: Postbox, peerIds: Set<PeerId>) -> Signal<ChatListSelectionOptions, NoError> {
func chatListSelectionOptions(postbox: Postbox, peerIds: Set<PeerId>, filterId: Int32?) -> Signal<ChatListSelectionOptions, NoError> {
if peerIds.isEmpty {
let key = PostboxViewKey.unreadCounts(items: [.total(nil)])
return postbox.combinedView(keys: [key])
|> map { view -> ChatListSelectionOptions in
var hasUnread = false
if let unreadCounts = view.views[key] as? UnreadMessageCountsView, let total = unreadCounts.total() {
for (_, counter) in total.1.absoluteCounters {
if counter.messageCount != 0 {
hasUnread = true
break
if let filterId = filterId {
return chatListFilterItems(postbox: postbox)
|> map { filterItems -> ChatListSelectionOptions in
for (filter, unreadCount, _) in filterItems.1 {
if filter.id == filterId {
return ChatListSelectionOptions(read: .all(enabled: unreadCount != 0), delete: false)
}
}
return ChatListSelectionOptions(read: .all(enabled: false), delete: false)
}
return ChatListSelectionOptions(read: .all(enabled: hasUnread), delete: false)
|> distinctUntilChanged
} else {
let key = PostboxViewKey.unreadCounts(items: [.total(nil)])
return postbox.combinedView(keys: [key])
|> map { view -> ChatListSelectionOptions in
var hasUnread = false
if let unreadCounts = view.views[key] as? UnreadMessageCountsView, let total = unreadCounts.total() {
for (_, counter) in total.1.absoluteCounters {
if counter.messageCount != 0 {
hasUnread = true
break
}
}
}
return ChatListSelectionOptions(read: .all(enabled: hasUnread), delete: false)
}
|> distinctUntilChanged
}
|> distinctUntilChanged
} else {
let items: [UnreadMessageCountsItem] = peerIds.map(UnreadMessageCountsItem.peer)
let key = PostboxViewKey.unreadCounts(items: items)