mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Folder improvements
This commit is contained in:
@@ -1236,6 +1236,16 @@ public final class Transaction {
|
||||
assert(!self.disposed)
|
||||
return self.postbox!.messageHistoryThreadPinnedTable.get(peerId: peerId)
|
||||
}
|
||||
|
||||
func addChatHidden(peerId: PeerId) -> Int {
|
||||
assert(!self.disposed)
|
||||
return self.postbox!.addChatHidden(peerId: peerId)
|
||||
}
|
||||
|
||||
func removeChatHidden(peerId: PeerId, index: Int) {
|
||||
assert(!self.disposed)
|
||||
return self.postbox!.removeChatHidden(peerId: peerId, index: index)
|
||||
}
|
||||
}
|
||||
|
||||
public enum PostboxResult {
|
||||
@@ -1470,6 +1480,40 @@ final class PostboxImpl {
|
||||
private var currentUpdatedPeerThreadCombinedStates = Set<PeerId>()
|
||||
private var currentUpdatedPinnedThreads = Set<PeerId>()
|
||||
|
||||
private var currentHiddenChatIds: [PeerId: Bag<Void>] = [:]
|
||||
private var currentUpdatedHiddenPeerIds: Bool = false
|
||||
|
||||
var hiddenChatIds: Set<PeerId> {
|
||||
if self.currentHiddenChatIds.isEmpty {
|
||||
return Set()
|
||||
} else {
|
||||
var result = Set<PeerId>()
|
||||
for (peerId, bag) in self.currentHiddenChatIds {
|
||||
if !bag.isEmpty {
|
||||
result.insert(peerId)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func isChatHidden(peerId: PeerId) -> Bool {
|
||||
if let bag = self.currentHiddenChatIds[peerId], !bag.isEmpty {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var hasHiddenChatIds: Bool {
|
||||
for (_, bag) in self.currentHiddenChatIds {
|
||||
if !bag.isEmpty {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private var currentNeedsReindexUnreadCounters: Bool = false
|
||||
|
||||
private let statePipe: ValuePipe<PostboxCoding> = ValuePipe()
|
||||
@@ -2117,7 +2161,7 @@ final class PostboxImpl {
|
||||
|
||||
let updatedPeerTimeoutAttributes = self.peerTimeoutPropertiesTable.hasUpdates
|
||||
|
||||
let transaction = PostboxTransaction(currentUpdatedState: self.currentUpdatedState, currentPeerHoleOperations: self.currentPeerHoleOperations, currentOperationsByPeerId: self.currentOperationsByPeerId, chatListOperations: self.currentChatListOperations, currentUpdatedChatListInclusions: self.currentUpdatedChatListInclusions, currentUpdatedPeers: self.currentUpdatedPeers, currentUpdatedPeerNotificationSettings: self.currentUpdatedPeerNotificationSettings, currentUpdatedPeerNotificationBehaviorTimestamps: self.currentUpdatedPeerNotificationBehaviorTimestamps, currentUpdatedCachedPeerData: self.currentUpdatedCachedPeerData, currentUpdatedPeerPresences: currentUpdatedPeerPresences, currentUpdatedPeerChatListEmbeddedStates: self.currentUpdatedPeerChatListEmbeddedStates, currentUpdatedTotalUnreadStates: self.currentUpdatedTotalUnreadStates, currentUpdatedTotalUnreadSummaries: self.currentUpdatedGroupTotalUnreadSummaries, alteredInitialPeerCombinedReadStates: alteredInitialPeerCombinedReadStates, currentPeerMergedOperationLogOperations: self.currentPeerMergedOperationLogOperations, currentTimestampBasedMessageAttributesOperations: self.currentTimestampBasedMessageAttributesOperations, unsentMessageOperations: self.currentUnsentOperations, updatedSynchronizePeerReadStateOperations: self.currentUpdatedSynchronizeReadStateOperations, currentUpdatedGroupSummarySynchronizeOperations: self.currentUpdatedGroupSummarySynchronizeOperations, currentPreferencesOperations: self.currentPreferencesOperations, currentOrderedItemListOperations: self.currentOrderedItemListOperations, currentItemCollectionItemsOperations: self.currentItemCollectionItemsOperations, currentItemCollectionInfosOperations: self.currentItemCollectionInfosOperations, currentUpdatedPeerChatStates: self.currentUpdatedPeerChatStates, currentGlobalTagsOperations: self.currentGlobalTagsOperations, currentLocalTagsOperations: self.currentLocalTagsOperations, updatedMedia: self.currentUpdatedMedia, replaceRemoteContactCount: self.currentReplaceRemoteContactCount, replaceContactPeerIds: self.currentReplacedContactPeerIds, currentPendingMessageActionsOperations: self.currentPendingMessageActionsOperations, currentUpdatedMessageActionsSummaries: self.currentUpdatedMessageActionsSummaries, currentUpdatedMessageTagSummaries: self.currentUpdatedMessageTagSummaries, currentInvalidateMessageTagSummaries: self.currentInvalidateMessageTagSummaries, currentUpdatedPendingPeerNotificationSettings: self.currentUpdatedPendingPeerNotificationSettings, replacedAdditionalChatListItems: self.currentReplacedAdditionalChatListItems, updatedNoticeEntryKeys: self.currentUpdatedNoticeEntryKeys, updatedCacheEntryKeys: self.currentUpdatedCacheEntryKeys, currentUpdatedMasterClientId: currentUpdatedMasterClientId, updatedFailedMessagePeerIds: self.messageHistoryFailedTable.updatedPeerIds, updatedFailedMessageIds: self.messageHistoryFailedTable.updatedMessageIds, updatedGlobalNotificationSettings: self.currentNeedsReindexUnreadCounters, updatedPeerTimeoutAttributes: updatedPeerTimeoutAttributes, updatedMessageThreadPeerIds: updatedMessageThreadPeerIds, updatedPeerThreadCombinedStates: self.currentUpdatedPeerThreadCombinedStates, updatedPeerThreadsSummaries: Set(alteredInitialPeerThreadsSummaries.keys), updatedPinnedThreads: self.currentUpdatedPinnedThreads)
|
||||
let transaction = PostboxTransaction(currentUpdatedState: self.currentUpdatedState, currentPeerHoleOperations: self.currentPeerHoleOperations, currentOperationsByPeerId: self.currentOperationsByPeerId, chatListOperations: self.currentChatListOperations, currentUpdatedChatListInclusions: self.currentUpdatedChatListInclusions, currentUpdatedPeers: self.currentUpdatedPeers, currentUpdatedPeerNotificationSettings: self.currentUpdatedPeerNotificationSettings, currentUpdatedPeerNotificationBehaviorTimestamps: self.currentUpdatedPeerNotificationBehaviorTimestamps, currentUpdatedCachedPeerData: self.currentUpdatedCachedPeerData, currentUpdatedPeerPresences: currentUpdatedPeerPresences, currentUpdatedPeerChatListEmbeddedStates: self.currentUpdatedPeerChatListEmbeddedStates, currentUpdatedTotalUnreadStates: self.currentUpdatedTotalUnreadStates, currentUpdatedTotalUnreadSummaries: self.currentUpdatedGroupTotalUnreadSummaries, alteredInitialPeerCombinedReadStates: alteredInitialPeerCombinedReadStates, currentPeerMergedOperationLogOperations: self.currentPeerMergedOperationLogOperations, currentTimestampBasedMessageAttributesOperations: self.currentTimestampBasedMessageAttributesOperations, unsentMessageOperations: self.currentUnsentOperations, updatedSynchronizePeerReadStateOperations: self.currentUpdatedSynchronizeReadStateOperations, currentUpdatedGroupSummarySynchronizeOperations: self.currentUpdatedGroupSummarySynchronizeOperations, currentPreferencesOperations: self.currentPreferencesOperations, currentOrderedItemListOperations: self.currentOrderedItemListOperations, currentItemCollectionItemsOperations: self.currentItemCollectionItemsOperations, currentItemCollectionInfosOperations: self.currentItemCollectionInfosOperations, currentUpdatedPeerChatStates: self.currentUpdatedPeerChatStates, currentGlobalTagsOperations: self.currentGlobalTagsOperations, currentLocalTagsOperations: self.currentLocalTagsOperations, updatedMedia: self.currentUpdatedMedia, replaceRemoteContactCount: self.currentReplaceRemoteContactCount, replaceContactPeerIds: self.currentReplacedContactPeerIds, currentPendingMessageActionsOperations: self.currentPendingMessageActionsOperations, currentUpdatedMessageActionsSummaries: self.currentUpdatedMessageActionsSummaries, currentUpdatedMessageTagSummaries: self.currentUpdatedMessageTagSummaries, currentInvalidateMessageTagSummaries: self.currentInvalidateMessageTagSummaries, currentUpdatedPendingPeerNotificationSettings: self.currentUpdatedPendingPeerNotificationSettings, replacedAdditionalChatListItems: self.currentReplacedAdditionalChatListItems, updatedNoticeEntryKeys: self.currentUpdatedNoticeEntryKeys, updatedCacheEntryKeys: self.currentUpdatedCacheEntryKeys, currentUpdatedMasterClientId: currentUpdatedMasterClientId, updatedFailedMessagePeerIds: self.messageHistoryFailedTable.updatedPeerIds, updatedFailedMessageIds: self.messageHistoryFailedTable.updatedMessageIds, updatedGlobalNotificationSettings: self.currentNeedsReindexUnreadCounters, updatedPeerTimeoutAttributes: updatedPeerTimeoutAttributes, updatedMessageThreadPeerIds: updatedMessageThreadPeerIds, updatedPeerThreadCombinedStates: self.currentUpdatedPeerThreadCombinedStates, updatedPeerThreadsSummaries: Set(alteredInitialPeerThreadsSummaries.keys), updatedPinnedThreads: self.currentUpdatedPinnedThreads, updatedHiddenPeerIds: self.currentUpdatedHiddenPeerIds)
|
||||
var updatedTransactionState: Int64?
|
||||
var updatedMasterClientId: Int64?
|
||||
if !transaction.isEmpty {
|
||||
@@ -2171,6 +2215,7 @@ final class PostboxImpl {
|
||||
self.currentUpdatedPendingPeerNotificationSettings.removeAll()
|
||||
self.currentGroupIdsWithUpdatedReadStats.removeAll()
|
||||
self.currentUpdatedPinnedThreads.removeAll()
|
||||
self.currentUpdatedHiddenPeerIds = false
|
||||
self.currentNeedsReindexUnreadCounters = false
|
||||
|
||||
for table in self.tables {
|
||||
@@ -3623,6 +3668,36 @@ final class PostboxImpl {
|
||||
return disposable
|
||||
}
|
||||
|
||||
public func addHiddenChatFilterAndChatIds(peerIds: [PeerId]) -> Disposable {
|
||||
let disposable = MetaDisposable()
|
||||
|
||||
let queue = self.queue
|
||||
let _ = (self.transaction { transaction -> [PeerId: Int] in
|
||||
var peerIndices: [PeerId: Int] = [:]
|
||||
for peerId in peerIds {
|
||||
peerIndices[peerId] = transaction.addChatHidden(peerId: peerId)
|
||||
}
|
||||
return peerIndices
|
||||
}).start(next: { peerIndices in
|
||||
disposable.set(ActionDisposable { [weak self] in
|
||||
queue.async {
|
||||
guard let `self` = self else {
|
||||
return
|
||||
}
|
||||
let _ = (self.transaction { transaction -> Void in
|
||||
for peerId in peerIds {
|
||||
if let index = peerIndices[peerId] {
|
||||
transaction.removeChatHidden(peerId: peerId, index: index)
|
||||
}
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return disposable
|
||||
}
|
||||
|
||||
fileprivate func scanMessages(peerId: PeerId, namespace: MessageId.Namespace, tag: MessageTags, _ f: (Message) -> Bool) {
|
||||
var index = MessageIndex.lowerBound(peerId: peerId, namespace: namespace)
|
||||
while true {
|
||||
@@ -3812,6 +3887,25 @@ final class PostboxImpl {
|
||||
self.messageHistoryThreadPinnedTable.set(peerId: peerId, threadIds: threadIds)
|
||||
}
|
||||
|
||||
fileprivate func addChatHidden(peerId: PeerId) -> Int {
|
||||
let bag: Bag<Void>
|
||||
if let current = self.currentHiddenChatIds[peerId] {
|
||||
bag = current
|
||||
} else {
|
||||
bag = Bag()
|
||||
self.currentHiddenChatIds[peerId] = bag
|
||||
}
|
||||
self.currentUpdatedHiddenPeerIds = true
|
||||
return bag.add(Void())
|
||||
}
|
||||
|
||||
fileprivate func removeChatHidden(peerId: PeerId, index: Int) {
|
||||
if let current = self.currentHiddenChatIds[peerId] {
|
||||
current.remove(index)
|
||||
self.currentUpdatedHiddenPeerIds = true
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func reindexUnreadCounters(currentTransaction: Transaction) {
|
||||
self.groupMessageStatsTable.removeAll()
|
||||
let _ = CFAbsoluteTimeGetCurrent()
|
||||
@@ -4414,6 +4508,16 @@ public class Postbox {
|
||||
|
||||
return disposable
|
||||
}
|
||||
|
||||
public func addHiddenChatIds(peerIds: [PeerId]) -> Disposable {
|
||||
let disposable = MetaDisposable()
|
||||
|
||||
self.impl.with { impl in
|
||||
disposable.set(impl.addHiddenChatFilterAndChatIds(peerIds: peerIds))
|
||||
}
|
||||
|
||||
return disposable
|
||||
}
|
||||
|
||||
public func isMasterClient() -> Signal<Bool, NoError> {
|
||||
return Signal { subscriber in
|
||||
|
||||
Reference in New Issue
Block a user