mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
failed messages view [skip ci]
This commit is contained in:
parent
aac2447dd0
commit
884993d740
30
submodules/Postbox/Sources/FailedMessagesView.swift
Normal file
30
submodules/Postbox/Sources/FailedMessagesView.swift
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
final class MutableFailedMessageIdsView {
|
||||||
|
let peerId: PeerId
|
||||||
|
var ids: Set<MessageId>
|
||||||
|
|
||||||
|
init(peerId: PeerId, ids: [MessageId]) {
|
||||||
|
self.peerId = peerId
|
||||||
|
self.ids = Set(ids)
|
||||||
|
}
|
||||||
|
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
|
||||||
|
let ids = transaction.updatedFailedMessageIds.filter { $0.peerId == self.peerId }
|
||||||
|
let updated = ids != self.ids
|
||||||
|
self.ids = ids
|
||||||
|
return updated
|
||||||
|
}
|
||||||
|
|
||||||
|
func immutableView() -> FailedMessageIdsView {
|
||||||
|
return FailedMessageIdsView(self.ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public final class FailedMessageIdsView {
|
||||||
|
public let ids: Set<MessageId>
|
||||||
|
|
||||||
|
fileprivate init(_ ids: Set<MessageId>) {
|
||||||
|
self.ids = ids
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,8 @@ final class MessageHistoryFailedTable: Table {
|
|||||||
private let sharedKey = ValueBoxKey(length: 8 + 4 + 4)
|
private let sharedKey = ValueBoxKey(length: 8 + 4 + 4)
|
||||||
|
|
||||||
private(set) var updatedPeerIds = Set<PeerId>()
|
private(set) var updatedPeerIds = Set<PeerId>()
|
||||||
|
private(set) var updatedMessageIds = Set<MessageId>()
|
||||||
|
|
||||||
private func key(_ id: MessageId) -> ValueBoxKey {
|
private func key(_ id: MessageId) -> ValueBoxKey {
|
||||||
self.sharedKey.setInt64(0, value: id.peerId.toInt64())
|
self.sharedKey.setInt64(0, value: id.peerId.toInt64())
|
||||||
self.sharedKey.setInt32(8, value: id.namespace)
|
self.sharedKey.setInt32(8, value: id.namespace)
|
||||||
@ -32,11 +33,30 @@ final class MessageHistoryFailedTable: Table {
|
|||||||
func add(_ id: MessageId) {
|
func add(_ id: MessageId) {
|
||||||
self.valueBox.set(self.table, key: self.key(id), value: MemoryBuffer())
|
self.valueBox.set(self.table, key: self.key(id), value: MemoryBuffer())
|
||||||
self.updatedPeerIds.insert(id.peerId)
|
self.updatedPeerIds.insert(id.peerId)
|
||||||
|
self.updatedMessageIds.insert(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove(_ id: MessageId) {
|
func remove(_ id: MessageId) {
|
||||||
self.valueBox.remove(self.table, key: self.key(id), secure: false)
|
self.valueBox.remove(self.table, key: self.key(id), secure: false)
|
||||||
self.updatedPeerIds.insert(id.peerId)
|
self.updatedPeerIds.insert(id.peerId)
|
||||||
|
self.updatedMessageIds.remove(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(peerId:PeerId) -> [MessageId] {
|
||||||
|
var ids:[MessageId] = []
|
||||||
|
self.valueBox.range(self.table, start: self.lowerBound(peerId: peerId), end: self.upperBound(peerId: peerId), keys: { key in
|
||||||
|
|
||||||
|
let peerId = PeerId(key.getInt64(0))
|
||||||
|
let namespace = key.getInt32(8)
|
||||||
|
let id = key.getInt32(8 + 4)
|
||||||
|
ids.append(MessageId(peerId: peerId, namespace: namespace, id: id))
|
||||||
|
|
||||||
|
return false
|
||||||
|
}, limit: 100)
|
||||||
|
|
||||||
|
self.updatedMessageIds = self.updatedMessageIds.union(ids)
|
||||||
|
|
||||||
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(peerId: PeerId) -> Bool {
|
func contains(peerId: PeerId) -> Bool {
|
||||||
|
@ -107,6 +107,14 @@ public final class Transaction {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public func failedMessageIds(for peerId: PeerId) -> [MessageId] {
|
||||||
|
assert(!self.disposed)
|
||||||
|
if let postbox = self.postbox {
|
||||||
|
return postbox.failedMessageIds(for: peerId)
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func deleteMessagesWithGlobalIds(_ ids: [Int32], forEachMedia: (Media) -> Void) {
|
public func deleteMessagesWithGlobalIds(_ ids: [Int32], forEachMedia: (Media) -> Void) {
|
||||||
assert(!self.disposed)
|
assert(!self.disposed)
|
||||||
@ -1703,7 +1711,7 @@ public final class Postbox {
|
|||||||
let transactionParticipationInTotalUnreadCountUpdates = self.peerNotificationSettingsTable.transactionParticipationInTotalUnreadCountUpdates(postbox: self)
|
let transactionParticipationInTotalUnreadCountUpdates = self.peerNotificationSettingsTable.transactionParticipationInTotalUnreadCountUpdates(postbox: self)
|
||||||
self.chatListIndexTable.commitWithTransaction(postbox: self, alteredInitialPeerCombinedReadStates: alteredInitialPeerCombinedReadStates, updatedPeers: updatedPeers, transactionParticipationInTotalUnreadCountUpdates: transactionParticipationInTotalUnreadCountUpdates, updatedRootUnreadState: &self.currentUpdatedTotalUnreadState, updatedGroupTotalUnreadSummaries: &self.currentUpdatedGroupTotalUnreadSummaries, currentUpdatedGroupSummarySynchronizeOperations: &self.currentUpdatedGroupSummarySynchronizeOperations)
|
self.chatListIndexTable.commitWithTransaction(postbox: self, alteredInitialPeerCombinedReadStates: alteredInitialPeerCombinedReadStates, updatedPeers: updatedPeers, transactionParticipationInTotalUnreadCountUpdates: transactionParticipationInTotalUnreadCountUpdates, updatedRootUnreadState: &self.currentUpdatedTotalUnreadState, updatedGroupTotalUnreadSummaries: &self.currentUpdatedGroupTotalUnreadSummaries, currentUpdatedGroupSummarySynchronizeOperations: &self.currentUpdatedGroupSummarySynchronizeOperations)
|
||||||
|
|
||||||
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, currentUpdatedTotalUnreadState: self.currentUpdatedTotalUnreadState, 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)
|
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, currentUpdatedTotalUnreadState: self.currentUpdatedTotalUnreadState, 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)
|
||||||
var updatedTransactionState: Int64?
|
var updatedTransactionState: Int64?
|
||||||
var updatedMasterClientId: Int64?
|
var updatedMasterClientId: Int64?
|
||||||
if !transaction.isEmpty {
|
if !transaction.isEmpty {
|
||||||
@ -1772,6 +1780,9 @@ public final class Postbox {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
fileprivate func failedMessageIds(for peerId: PeerId) -> [MessageId] {
|
||||||
|
return self.messageHistoryFailedTable.get(peerId: peerId)
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func messageIdForGloballyUniqueMessageId(peerId: PeerId, id: Int64) -> MessageId? {
|
fileprivate func messageIdForGloballyUniqueMessageId(peerId: PeerId, id: Int64) -> MessageId? {
|
||||||
return self.globallyUniqueMessageIdsTable.get(peerId: peerId, globallyUniqueId: id)
|
return self.globallyUniqueMessageIdsTable.get(peerId: peerId, globallyUniqueId: id)
|
||||||
@ -3185,4 +3196,25 @@ public final class Postbox {
|
|||||||
self.currentUpdatedGroupTotalUnreadSummaries[groupId] = summary
|
self.currentUpdatedGroupTotalUnreadSummaries[groupId] = summary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func failedMessageIdsView(peerId: PeerId) -> Signal<FailedMessageIdsView, NoError> {
|
||||||
|
return self.transactionSignal { subscriber, transaction in
|
||||||
|
let view = MutableFailedMessageIdsView(peerId: peerId, ids: self.failedMessageIds(for: peerId))
|
||||||
|
let (index, signal) = self.viewTracker.addFailedMessageIdsView(view)
|
||||||
|
subscriber.putNext(view.immutableView())
|
||||||
|
let disposable = signal.start(next: { next in
|
||||||
|
subscriber.putNext(next)
|
||||||
|
})
|
||||||
|
|
||||||
|
return ActionDisposable { [weak self] in
|
||||||
|
disposable.dispose()
|
||||||
|
if let strongSelf = self {
|
||||||
|
strongSelf.queue.async {
|
||||||
|
strongSelf.viewTracker.removeFailedMessageIdsView(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,9 @@ final class PostboxTransaction {
|
|||||||
let updatedNoticeEntryKeys: Set<NoticeEntryKey>
|
let updatedNoticeEntryKeys: Set<NoticeEntryKey>
|
||||||
let updatedCacheEntryKeys: Set<ItemCacheEntryId>
|
let updatedCacheEntryKeys: Set<ItemCacheEntryId>
|
||||||
let updatedFailedMessagePeerIds: Set<PeerId>
|
let updatedFailedMessagePeerIds: Set<PeerId>
|
||||||
|
let updatedFailedMessageIds: Set<MessageId>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var isEmpty: Bool {
|
var isEmpty: Bool {
|
||||||
if currentUpdatedState != nil {
|
if currentUpdatedState != nil {
|
||||||
@ -163,10 +166,13 @@ final class PostboxTransaction {
|
|||||||
if !updatedFailedMessagePeerIds.isEmpty {
|
if !updatedFailedMessagePeerIds.isEmpty {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if !updatedFailedMessageIds.isEmpty {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
init(currentUpdatedState: PostboxCoding?, currentPeerHoleOperations: [MessageHistoryIndexHoleOperationKey: [MessageHistoryIndexHoleOperation]] = [:], currentOperationsByPeerId: [PeerId: [MessageHistoryOperation]], chatListOperations: [PeerGroupId: [ChatListOperation]], currentUpdatedChatListInclusions: [PeerId: PeerChatListInclusion], currentUpdatedPeers: [PeerId: Peer], currentUpdatedPeerNotificationSettings: [PeerId: PeerNotificationSettings], currentUpdatedPeerNotificationBehaviorTimestamps: [PeerId: PeerNotificationSettingsBehaviorTimestamp], currentUpdatedCachedPeerData: [PeerId: CachedPeerData], currentUpdatedPeerPresences: [PeerId: PeerPresence], currentUpdatedPeerChatListEmbeddedStates: [PeerId: PeerChatListEmbeddedInterfaceState?], currentUpdatedTotalUnreadState: ChatListTotalUnreadState?, currentUpdatedTotalUnreadSummaries: [PeerGroupId: PeerGroupUnreadCountersCombinedSummary], alteredInitialPeerCombinedReadStates: [PeerId: CombinedPeerReadState], currentPeerMergedOperationLogOperations: [PeerMergedOperationLogOperation], currentTimestampBasedMessageAttributesOperations: [TimestampBasedMessageAttributesOperation], unsentMessageOperations: [IntermediateMessageHistoryUnsentOperation], updatedSynchronizePeerReadStateOperations: [PeerId: PeerReadStateSynchronizationOperation?], currentUpdatedGroupSummarySynchronizeOperations: [PeerGroupAndNamespace: Bool], currentPreferencesOperations: [PreferencesOperation], currentOrderedItemListOperations: [Int32: [OrderedItemListOperation]], currentItemCollectionItemsOperations: [ItemCollectionId: [ItemCollectionItemsOperation]], currentItemCollectionInfosOperations: [ItemCollectionInfosOperation], currentUpdatedPeerChatStates: Set<PeerId>, currentGlobalTagsOperations: [GlobalMessageHistoryTagsOperation], currentLocalTagsOperations: [IntermediateMessageHistoryLocalTagsOperation], updatedMedia: [MediaId: Media?], replaceRemoteContactCount: Int32?, replaceContactPeerIds: Set<PeerId>?, currentPendingMessageActionsOperations: [PendingMessageActionsOperation], currentUpdatedMessageActionsSummaries: [PendingMessageActionsSummaryKey: Int32], currentUpdatedMessageTagSummaries: [MessageHistoryTagsSummaryKey: MessageHistoryTagNamespaceSummary], currentInvalidateMessageTagSummaries: [InvalidatedMessageHistoryTagsSummaryEntryOperation], currentUpdatedPendingPeerNotificationSettings: Set<PeerId>, replacedAdditionalChatListItems: [PeerId]?, updatedNoticeEntryKeys: Set<NoticeEntryKey>, updatedCacheEntryKeys: Set<ItemCacheEntryId>, currentUpdatedMasterClientId: Int64?, updatedFailedMessagePeerIds: Set<PeerId>) {
|
init(currentUpdatedState: PostboxCoding?, currentPeerHoleOperations: [MessageHistoryIndexHoleOperationKey: [MessageHistoryIndexHoleOperation]] = [:], currentOperationsByPeerId: [PeerId: [MessageHistoryOperation]], chatListOperations: [PeerGroupId: [ChatListOperation]], currentUpdatedChatListInclusions: [PeerId: PeerChatListInclusion], currentUpdatedPeers: [PeerId: Peer], currentUpdatedPeerNotificationSettings: [PeerId: PeerNotificationSettings], currentUpdatedPeerNotificationBehaviorTimestamps: [PeerId: PeerNotificationSettingsBehaviorTimestamp], currentUpdatedCachedPeerData: [PeerId: CachedPeerData], currentUpdatedPeerPresences: [PeerId: PeerPresence], currentUpdatedPeerChatListEmbeddedStates: [PeerId: PeerChatListEmbeddedInterfaceState?], currentUpdatedTotalUnreadState: ChatListTotalUnreadState?, currentUpdatedTotalUnreadSummaries: [PeerGroupId: PeerGroupUnreadCountersCombinedSummary], alteredInitialPeerCombinedReadStates: [PeerId: CombinedPeerReadState], currentPeerMergedOperationLogOperations: [PeerMergedOperationLogOperation], currentTimestampBasedMessageAttributesOperations: [TimestampBasedMessageAttributesOperation], unsentMessageOperations: [IntermediateMessageHistoryUnsentOperation], updatedSynchronizePeerReadStateOperations: [PeerId: PeerReadStateSynchronizationOperation?], currentUpdatedGroupSummarySynchronizeOperations: [PeerGroupAndNamespace: Bool], currentPreferencesOperations: [PreferencesOperation], currentOrderedItemListOperations: [Int32: [OrderedItemListOperation]], currentItemCollectionItemsOperations: [ItemCollectionId: [ItemCollectionItemsOperation]], currentItemCollectionInfosOperations: [ItemCollectionInfosOperation], currentUpdatedPeerChatStates: Set<PeerId>, currentGlobalTagsOperations: [GlobalMessageHistoryTagsOperation], currentLocalTagsOperations: [IntermediateMessageHistoryLocalTagsOperation], updatedMedia: [MediaId: Media?], replaceRemoteContactCount: Int32?, replaceContactPeerIds: Set<PeerId>?, currentPendingMessageActionsOperations: [PendingMessageActionsOperation], currentUpdatedMessageActionsSummaries: [PendingMessageActionsSummaryKey: Int32], currentUpdatedMessageTagSummaries: [MessageHistoryTagsSummaryKey: MessageHistoryTagNamespaceSummary], currentInvalidateMessageTagSummaries: [InvalidatedMessageHistoryTagsSummaryEntryOperation], currentUpdatedPendingPeerNotificationSettings: Set<PeerId>, replacedAdditionalChatListItems: [PeerId]?, updatedNoticeEntryKeys: Set<NoticeEntryKey>, updatedCacheEntryKeys: Set<ItemCacheEntryId>, currentUpdatedMasterClientId: Int64?, updatedFailedMessagePeerIds: Set<PeerId>, updatedFailedMessageIds: Set<MessageId>) {
|
||||||
self.currentUpdatedState = currentUpdatedState
|
self.currentUpdatedState = currentUpdatedState
|
||||||
self.currentPeerHoleOperations = currentPeerHoleOperations
|
self.currentPeerHoleOperations = currentPeerHoleOperations
|
||||||
self.currentOperationsByPeerId = currentOperationsByPeerId
|
self.currentOperationsByPeerId = currentOperationsByPeerId
|
||||||
@ -206,5 +212,6 @@ final class PostboxTransaction {
|
|||||||
self.updatedNoticeEntryKeys = updatedNoticeEntryKeys
|
self.updatedNoticeEntryKeys = updatedNoticeEntryKeys
|
||||||
self.updatedCacheEntryKeys = updatedCacheEntryKeys
|
self.updatedCacheEntryKeys = updatedCacheEntryKeys
|
||||||
self.updatedFailedMessagePeerIds = updatedFailedMessagePeerIds
|
self.updatedFailedMessagePeerIds = updatedFailedMessagePeerIds
|
||||||
|
self.updatedFailedMessageIds = updatedFailedMessageIds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,10 @@ final class ViewTracker {
|
|||||||
private var multiplePeersViews = Bag<(MutableMultiplePeersView, ValuePipe<MultiplePeersView>)>()
|
private var multiplePeersViews = Bag<(MutableMultiplePeersView, ValuePipe<MultiplePeersView>)>()
|
||||||
private var itemCollectionsViews = Bag<(MutableItemCollectionsView, ValuePipe<ItemCollectionsView>)>()
|
private var itemCollectionsViews = Bag<(MutableItemCollectionsView, ValuePipe<ItemCollectionsView>)>()
|
||||||
|
|
||||||
|
|
||||||
|
private var failedMessageIdsViews = Bag<(MutableFailedMessageIdsView, ValuePipe<FailedMessageIdsView>)>()
|
||||||
|
|
||||||
|
|
||||||
init(queue: Queue, renderMessage: @escaping (IntermediateMessage) -> Message, getPeer: @escaping (PeerId) -> Peer?, getPeerNotificationSettings: @escaping (PeerId) -> PeerNotificationSettings?, getCachedPeerData: @escaping (PeerId) -> CachedPeerData?, getPeerPresence: @escaping (PeerId) -> PeerPresence?, getTotalUnreadState: @escaping () -> ChatListTotalUnreadState, getPeerReadState: @escaping (PeerId) -> CombinedPeerReadState?, operationLogGetOperations: @escaping (PeerOperationLogTag, Int32, Int) -> [PeerMergedOperationLogEntry], operationLogGetTailIndex: @escaping (PeerOperationLogTag) -> Int32?, getTimestampBasedMessageAttributesHead: @escaping (UInt16) -> TimestampBasedMessageAttributesEntry?, getPreferencesEntry: @escaping (ValueBoxKey) -> PreferencesEntry?, unsentMessageIds: [MessageId], synchronizePeerReadStateOperations: [PeerId: PeerReadStateSynchronizationOperation]) {
|
init(queue: Queue, renderMessage: @escaping (IntermediateMessage) -> Message, getPeer: @escaping (PeerId) -> Peer?, getPeerNotificationSettings: @escaping (PeerId) -> PeerNotificationSettings?, getCachedPeerData: @escaping (PeerId) -> CachedPeerData?, getPeerPresence: @escaping (PeerId) -> PeerPresence?, getTotalUnreadState: @escaping () -> ChatListTotalUnreadState, getPeerReadState: @escaping (PeerId) -> CombinedPeerReadState?, operationLogGetOperations: @escaping (PeerOperationLogTag, Int32, Int) -> [PeerMergedOperationLogEntry], operationLogGetTailIndex: @escaping (PeerOperationLogTag) -> Int32?, getTimestampBasedMessageAttributesHead: @escaping (UInt16) -> TimestampBasedMessageAttributesEntry?, getPreferencesEntry: @escaping (ValueBoxKey) -> PreferencesEntry?, unsentMessageIds: [MessageId], synchronizePeerReadStateOperations: [PeerId: PeerReadStateSynchronizationOperation]) {
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.renderMessage = renderMessage
|
self.renderMessage = renderMessage
|
||||||
@ -438,6 +442,12 @@ final class ViewTracker {
|
|||||||
pipe.putNext(mutableView.immutableView())
|
pipe.putNext(mutableView.immutableView())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (view, pipe) in self.failedMessageIdsViews.copyItems() {
|
||||||
|
if view.replay(postbox: postbox, transaction: transaction) {
|
||||||
|
pipe.putNext(view.immutableView())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateTrackedChatListHoles() {
|
private func updateTrackedChatListHoles() {
|
||||||
@ -584,4 +594,17 @@ final class ViewTracker {
|
|||||||
return disposable
|
return disposable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addFailedMessageIdsView(_ view: MutableFailedMessageIdsView) -> (Bag<(MutableFailedMessageIdsView, ValuePipe<FailedMessageIdsView>)>.Index, Signal<FailedMessageIdsView, NoError>) {
|
||||||
|
let record = (view, ValuePipe<FailedMessageIdsView>())
|
||||||
|
let index = self.failedMessageIdsViews.add(record)
|
||||||
|
|
||||||
|
return (index, record.1.signal())
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeFailedMessageIdsView(_ index: Bag<(MutableFailedMessageIdsView, ValuePipe<PeerId?>)>.Index) {
|
||||||
|
self.failedMessageIdsViews.remove(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@ import Postbox
|
|||||||
import TelegramApi
|
import TelegramApi
|
||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
|
|
||||||
public func groupsInCommon(account:Account, peerId:PeerId) -> Signal<[PeerId], NoError> {
|
public func groupsInCommon(account:Account, peerId:PeerId) -> Signal<[Peer], NoError> {
|
||||||
return account.postbox.transaction { transaction -> Signal<[PeerId], NoError> in
|
return account.postbox.transaction { transaction -> Signal<[Peer], NoError> in
|
||||||
if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) {
|
if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) {
|
||||||
return account.network.request(Api.functions.messages.getCommonChats(userId: inputUser, maxId: 0, limit: 100))
|
return account.network.request(Api.functions.messages.getCommonChats(userId: inputUser, maxId: 0, limit: 100))
|
||||||
|> retryRequest
|
|> retryRequest
|
||||||
|> mapToSignal { result -> Signal<[PeerId], NoError> in
|
|> mapToSignal { result -> Signal<[Peer], NoError> in
|
||||||
let chats: [Api.Chat]
|
let chats: [Api.Chat]
|
||||||
switch result {
|
switch result {
|
||||||
case let .chats(chats: apiChats):
|
case let .chats(chats: apiChats):
|
||||||
@ -17,7 +17,7 @@ public func groupsInCommon(account:Account, peerId:PeerId) -> Signal<[PeerId], N
|
|||||||
chats = apiChats
|
chats = apiChats
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.postbox.transaction { transaction -> [PeerId] in
|
return account.postbox.transaction { transaction -> [Peer] in
|
||||||
var peers:[Peer] = []
|
var peers:[Peer] = []
|
||||||
for chat in chats {
|
for chat in chats {
|
||||||
if let peer = parseTelegramGroupOrChannel(chat: chat) {
|
if let peer = parseTelegramGroupOrChannel(chat: chat) {
|
||||||
@ -27,7 +27,7 @@ public func groupsInCommon(account:Account, peerId:PeerId) -> Signal<[PeerId], N
|
|||||||
updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer? in
|
updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer? in
|
||||||
return updated
|
return updated
|
||||||
})
|
})
|
||||||
return peers.map {$0.id}
|
return peers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user