Various fixes

This commit is contained in:
Ilya Laktyushin
2022-11-09 22:00:38 +04:00
parent 117a1f6c22
commit 04bde13821
9 changed files with 89 additions and 50 deletions

View File

@@ -59,17 +59,31 @@ func chatListSelectionOptions(context: AccountContext, peerIds: Set<PeerId>, fil
func forumSelectionOptions(context: AccountContext, peerId: PeerId, threadIds: Set<Int64>, canDelete: Bool) -> Signal<ChatListSelectionOptions, NoError> {
if threadIds.isEmpty {
return context.engine.data.subscribe(TelegramEngine.EngineData.Item.Messages.PeerReadCounters(id: peerId))
|> map { counters -> ChatListSelectionOptions in
let threadIdsArray = Array(threadIds)
var threadSignals: [Signal<MessageHistoryThreadData?, NoError>] = []
for threadId in threadIdsArray {
threadSignals.append(
context.engine.data.get(TelegramEngine.EngineData.Item.Peer.ThreadData(id: peerId, threadId: threadId))
)
}
return combineLatest(threadSignals)
|> map { threadDatas -> ChatListSelectionOptions in
if threadIds.isEmpty {
return ChatListSelectionOptions(read: .selective(enabled: false), delete: false)
} else {
var hasUnread = false
if counters.isUnread {
hasUnread = true
for thread in threadDatas {
guard let thread = thread else {
continue
}
if thread.incomingUnreadCount > 0 {
hasUnread = true
break
}
}
return ChatListSelectionOptions(read: .all(enabled: hasUnread), delete: false)
return ChatListSelectionOptions(read: .selective(enabled: hasUnread), delete: canDelete)
}
|> distinctUntilChanged
} else {
return .single(ChatListSelectionOptions(read: .selective(enabled: false), delete: canDelete))
}
}