diff --git a/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift b/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift index 5806283b94..b160061fda 100644 --- a/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift +++ b/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift @@ -992,7 +992,7 @@ public final class AnimatedStickerNode: ASDisplayNode { let timerHolder = self.timer let frameSourceHolder = self.frameSource self.queue.async { [weak self] in - var maybeFrameSource: AnimatedStickerFrameSource? = frameSourceHolder.with { $0 }?.syncWith { $0 }?.value + var maybeFrameSource: AnimatedStickerFrameSource? = frameSourceHolder.with { $0 }?.syncWith { $0 }.value if maybeFrameSource == nil { let notifyUpdated: (() -> Void)? = nil if let directData = directData { @@ -1025,10 +1025,10 @@ public final class AnimatedStickerNode: ASDisplayNode { let frameRate = frameSource.frameRate let timer = SwiftSignalKit.Timer(timeout: 1.0 / Double(frameRate), repeat: !firstFrame, completion: { - let maybeFrame = frameQueue.syncWith { frameQueue in + let frame = frameQueue.syncWith { frameQueue in return frameQueue.take(draw: true) } - if let maybeFrame = maybeFrame, let frame = maybeFrame { + if let frame = frame { Queue.mainQueue().async { guard let strongSelf = self else { return @@ -1124,10 +1124,10 @@ public final class AnimatedStickerNode: ASDisplayNode { let frameRate = frameSource.frameRate let timer = SwiftSignalKit.Timer(timeout: 1.0 / Double(frameRate), repeat: !firstFrame, completion: { - let maybeFrame = frameQueue.syncWith { frameQueue in + let frame = frameQueue.syncWith { frameQueue in return frameQueue.take(draw: true) } - if let maybeFrame = maybeFrame, let frame = maybeFrame { + if let frame = frame { Queue.mainQueue().async { guard let strongSelf = self else { return @@ -1206,7 +1206,7 @@ public final class AnimatedStickerNode: ASDisplayNode { let frameSourceHolder = self.frameSource let timerHolder = self.timer self.queue.async { [weak self] in - var maybeFrameSource: AnimatedStickerFrameSource? = frameSourceHolder.with { $0 }?.syncWith { $0 }?.value + var maybeFrameSource: AnimatedStickerFrameSource? = frameSourceHolder.with { $0 }?.syncWith { $0 }.value if case .timestamp = position { } else { if let directData = directData { diff --git a/submodules/ChatListUI/Sources/TabBarChatListFilterController.swift b/submodules/ChatListUI/Sources/TabBarChatListFilterController.swift index 18159fa45a..448b94ec99 100644 --- a/submodules/ChatListUI/Sources/TabBarChatListFilterController.swift +++ b/submodules/ChatListUI/Sources/TabBarChatListFilterController.swift @@ -39,11 +39,8 @@ func chatListFilterItems(context: AccountContext) -> Signal<(Int, [(ChatListFilt keys.append(.basicPeer(peerId)) } - return combineLatest(queue: context.account.postbox.queue, - context.account.postbox.combinedView(keys: keys), - Signal.single(true) - ) - |> map { view, _ -> (Int, [(ChatListFilter, Int, Bool)]) in + return context.account.postbox.combinedView(keys: keys) + |> map { view -> (Int, [(ChatListFilter, Int, Bool)]) in guard let unreadCounts = view.views[unreadKey] as? UnreadMessageCountsView else { return (0, []) } diff --git a/submodules/Display/Source/ListView.swift b/submodules/Display/Source/ListView.swift index 9a4ab417cb..a19511a0db 100644 --- a/submodules/Display/Source/ListView.swift +++ b/submodules/Display/Source/ListView.swift @@ -1534,7 +1534,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture } }, node: { assert(Queue.mainQueue().isCurrent()) - return previousNode.syncWith({ $0 })! + return previousNode.syncWith({ $0 }) }, params: params, previousItem: previousItem, nextItem: nextItem, animation: updateAnimation, completion: { (layout, apply) in if Thread.isMainThread { if synchronous { @@ -1985,7 +1985,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture } }, node: { assert(Queue.mainQueue().isCurrent()) - return referenceNode.syncWith({ $0 })! + return referenceNode.syncWith({ $0 }) }, params: ListViewItemLayoutParams(width: state.visibleSize.width, leftInset: state.insets.left, rightInset: state.insets.right, availableHeight: state.visibleSize.height - state.insets.top - state.insets.bottom), previousItem: index == 0 ? nil : self.items[index - 1], nextItem: index == self.items.count - 1 ? nil : self.items[index + 1], animation: updateAnimation, completion: { layout, apply in var updatedState = state var updatedOperations = operations @@ -2424,7 +2424,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture var takenPreviousNodes = Set() for operation in operations { if case let .InsertNode(_, _, _, node, _, _) = operation { - takenPreviousNodes.insert(node.syncWith({ $0 })!) + takenPreviousNodes.insert(node.syncWith({ $0 })) } } @@ -2436,7 +2436,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture for operation in operations { switch operation { case let .InsertNode(index, offsetDirection, nodeAnimated, nodeObject, layout, apply): - let node = nodeObject.syncWith({ $0 })! + let node = nodeObject.syncWith({ $0 }) var previousFrame: CGRect? for (previousNode, frame) in previousApparentFrames { if previousNode === node { @@ -2499,7 +2499,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture var height: CGFloat? var previousLayout: ListViewItemNodeLayout? - let referenceNode = referenceNodeObject.syncWith({ $0 })! + let referenceNode = referenceNodeObject.syncWith({ $0 }) for (node, previousFrame) in previousApparentFrames { if node === referenceNode { diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift index aa9c8c692a..923718dfa5 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift @@ -198,7 +198,7 @@ private class LegacyPaintStickerEntity: LegacyPaintEntity { } return frame } - if let maybeFrame = maybeFrame, let frame = maybeFrame { + if let frame = maybeFrame { let image = render(width: frame.width, height: frame.height, bytesPerRow: frame.bytesPerRow, data: frame.data, type: frame.type) completion(image) strongSelf.cachedCIImage = image diff --git a/submodules/MediaPlayer/Sources/TimeBasedVideoPreload.swift b/submodules/MediaPlayer/Sources/TimeBasedVideoPreload.swift index b19c78c554..bdd451b19b 100644 --- a/submodules/MediaPlayer/Sources/TimeBasedVideoPreload.swift +++ b/submodules/MediaPlayer/Sources/TimeBasedVideoPreload.swift @@ -20,7 +20,9 @@ public func preloadVideoResource(postbox: Postbox, resourceReference: MediaResou |> deliverOn(queue) |> mapToSignal { result -> Signal in let result = result.syncWith({ $0 }) - if let videoBuffer = result?.buffers.videoBuffer, let impl = source.syncWith({ $0 }) { + if let videoBuffer = result.buffers.videoBuffer { + let impl = source.syncWith({ $0 }) + return impl.ensureHasFrames(until: min(duration, videoBuffer.duration.seconds)) |> ignoreValues |> castError(MediaFrameSourceSeekError.self) diff --git a/submodules/Postbox/Sources/AdditionalChatListItemsView.swift b/submodules/Postbox/Sources/AdditionalChatListItemsView.swift index 056cde03ca..4c54a00236 100644 --- a/submodules/Postbox/Sources/AdditionalChatListItemsView.swift +++ b/submodules/Postbox/Sources/AdditionalChatListItemsView.swift @@ -3,11 +3,11 @@ import Foundation final class MutableAdditionalChatListItemsView: MutablePostboxView { fileprivate var items: [AdditionalChatListItem] - init(postbox: Postbox) { + init(postbox: PostboxImpl) { self.items = postbox.additionalChatListItemsTable.get() } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if let items = transaction.replacedAdditionalChatListItems { self.items = items return true diff --git a/submodules/Postbox/Sources/AllChatListHolesView.swift b/submodules/Postbox/Sources/AllChatListHolesView.swift index 6f40b007c8..4e582e9ed6 100644 --- a/submodules/Postbox/Sources/AllChatListHolesView.swift +++ b/submodules/Postbox/Sources/AllChatListHolesView.swift @@ -5,13 +5,13 @@ final class MutableAllChatListHolesView: MutablePostboxView { private var holes = Set() fileprivate var latestHole: ChatListHole? - init(postbox: Postbox, groupId: PeerGroupId) { + init(postbox: PostboxImpl, groupId: PeerGroupId) { self.groupId = groupId self.holes = Set(postbox.chatListTable.allHoles(groupId: groupId)) self.latestHole = self.holes.max(by: { $0.index < $1.index }) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if let operations = transaction.chatListOperations[self.groupId] { var updated = false for operation in operations { diff --git a/submodules/Postbox/Sources/CachedItemView.swift b/submodules/Postbox/Sources/CachedItemView.swift index b1048fd3a6..64236036a6 100644 --- a/submodules/Postbox/Sources/CachedItemView.swift +++ b/submodules/Postbox/Sources/CachedItemView.swift @@ -4,12 +4,12 @@ final class MutableCachedItemView: MutablePostboxView { private let id: ItemCacheEntryId fileprivate var value: PostboxCoding? - init(postbox: Postbox, id: ItemCacheEntryId) { + init(postbox: PostboxImpl, id: ItemCacheEntryId) { self.id = id self.value = postbox.itemCacheTable.retrieve(id: id, metaTable: postbox.itemCacheMetaTable) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if transaction.updatedCacheEntryKeys.contains(self.id) { self.value = postbox.itemCacheTable.retrieve(id: id, metaTable: postbox.itemCacheMetaTable) return true diff --git a/submodules/Postbox/Sources/CachedPeerDataView.swift b/submodules/Postbox/Sources/CachedPeerDataView.swift index 825d4c9dd1..c3cb02ac7b 100644 --- a/submodules/Postbox/Sources/CachedPeerDataView.swift +++ b/submodules/Postbox/Sources/CachedPeerDataView.swift @@ -4,12 +4,12 @@ final class MutableCachedPeerDataView: MutablePostboxView { let peerId: PeerId var cachedPeerData: CachedPeerData? - init(postbox: Postbox, peerId: PeerId) { + init(postbox: PostboxImpl, peerId: PeerId) { self.peerId = peerId self.cachedPeerData = postbox.cachedPeerDataTable.get(peerId) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if let cachedPeerData = transaction.currentUpdatedCachedPeerData[self.peerId] { self.cachedPeerData = cachedPeerData return true diff --git a/submodules/Postbox/Sources/ChatListIndexTable.swift b/submodules/Postbox/Sources/ChatListIndexTable.swift index f44ade7157..5597871bef 100644 --- a/submodules/Postbox/Sources/ChatListIndexTable.swift +++ b/submodules/Postbox/Sources/ChatListIndexTable.swift @@ -170,7 +170,7 @@ final class ChatListIndexTable: Table { assert(self.updatedPreviousPeerCachedIndices.isEmpty) } - func commitWithTransaction(postbox: Postbox, alteredInitialPeerCombinedReadStates: [PeerId: CombinedPeerReadState], updatedPeers: [((Peer, Bool)?, (Peer, Bool))], transactionParticipationInTotalUnreadCountUpdates: (added: Set, removed: Set), updatedTotalUnreadStates: inout [PeerGroupId: ChatListTotalUnreadState], updatedGroupTotalUnreadSummaries: inout [PeerGroupId: PeerGroupUnreadCountersCombinedSummary], currentUpdatedGroupSummarySynchronizeOperations: inout [PeerGroupAndNamespace: Bool]) { + func commitWithTransaction(postbox: PostboxImpl, alteredInitialPeerCombinedReadStates: [PeerId: CombinedPeerReadState], updatedPeers: [((Peer, Bool)?, (Peer, Bool))], transactionParticipationInTotalUnreadCountUpdates: (added: Set, removed: Set), updatedTotalUnreadStates: inout [PeerGroupId: ChatListTotalUnreadState], updatedGroupTotalUnreadSummaries: inout [PeerGroupId: PeerGroupUnreadCountersCombinedSummary], currentUpdatedGroupSummarySynchronizeOperations: inout [PeerGroupAndNamespace: Bool]) { var updatedPeerTags: [PeerId: (previous: PeerSummaryCounterTags, updated: PeerSummaryCounterTags)] = [:] for (previous, updated) in updatedPeers { let previousTags: PeerSummaryCounterTags @@ -556,7 +556,7 @@ final class ChatListIndexTable: Table { assert(self.updatedPreviousPeerCachedIndices.isEmpty) } - func debugReindexUnreadCounts(postbox: Postbox) -> ([PeerGroupId: ChatListTotalUnreadState], [PeerGroupId: PeerGroupUnreadCountersCombinedSummary]) { + func debugReindexUnreadCounts(postbox: PostboxImpl) -> ([PeerGroupId: ChatListTotalUnreadState], [PeerGroupId: PeerGroupUnreadCountersCombinedSummary]) { let globalNotificationSettings = postbox.getGlobalNotificationSettings() var peerIds: [PeerId] = [] @@ -643,7 +643,7 @@ final class ChatListIndexTable: Table { return (totalStates, summaries) } - func reindexPeerGroupUnreadCounts(postbox: Postbox, groupId: PeerGroupId) -> PeerGroupUnreadCountersCombinedSummary { + func reindexPeerGroupUnreadCounts(postbox: PostboxImpl, groupId: PeerGroupId) -> PeerGroupUnreadCountersCombinedSummary { var summary = PeerGroupUnreadCountersCombinedSummary(namespaces: [:]) postbox.chatListTable.forEachPeer(groupId: groupId, { peerId in diff --git a/submodules/Postbox/Sources/ChatListTable.swift b/submodules/Postbox/Sources/ChatListTable.swift index 107c7860d5..b33ac30fac 100644 --- a/submodules/Postbox/Sources/ChatListTable.swift +++ b/submodules/Postbox/Sources/ChatListTable.swift @@ -245,7 +245,7 @@ final class ChatListTable: Table { } } - func getUnreadChatListPeerIds(postbox: Postbox, groupId: PeerGroupId, filterPredicate: ChatListFilterPredicate?) -> [PeerId] { + func getUnreadChatListPeerIds(postbox: PostboxImpl, groupId: PeerGroupId, filterPredicate: ChatListFilterPredicate?) -> [PeerId] { let globalNotificationSettings = postbox.getGlobalNotificationSettings() var result: [PeerId] = [] @@ -797,7 +797,7 @@ final class ChatListTable: Table { return entries } - func getRelativeUnreadChatListIndex(postbox: Postbox, filtered: Bool, position: ChatListRelativePosition, groupId: PeerGroupId) -> ChatListIndex? { + func getRelativeUnreadChatListIndex(postbox: PostboxImpl, filtered: Bool, position: ChatListRelativePosition, groupId: PeerGroupId) -> ChatListIndex? { var result: ChatListIndex? let lower: ValueBoxKey diff --git a/submodules/Postbox/Sources/ChatListView.swift b/submodules/Postbox/Sources/ChatListView.swift index 4c32c8dce4..e3f44805e3 100644 --- a/submodules/Postbox/Sources/ChatListView.swift +++ b/submodules/Postbox/Sources/ChatListView.swift @@ -337,7 +337,7 @@ final class MutableChatListView { private var additionalItems: [AdditionalChatListItem] = [] fileprivate var additionalItemEntries: [MutableChatListAdditionalItemEntry] = [] - init(postbox: Postbox, groupId: PeerGroupId, filterPredicate: ChatListFilterPredicate?, aroundIndex: ChatListIndex, count: Int, summaryComponents: ChatListEntrySummaryComponents) { + init(postbox: PostboxImpl, groupId: PeerGroupId, filterPredicate: ChatListFilterPredicate?, aroundIndex: ChatListIndex, count: Int, summaryComponents: ChatListEntrySummaryComponents) { self.groupId = groupId self.filterPredicate = filterPredicate self.summaryComponents = summaryComponents @@ -382,7 +382,7 @@ final class MutableChatListView { } } - private func reloadGroups(postbox: Postbox) { + private func reloadGroups(postbox: PostboxImpl) { self.groupEntries.removeAll() if case .root = self.groupId, self.filterPredicate == nil { for groupId in postbox.chatListTable.existingGroups() { @@ -451,7 +451,7 @@ final class MutableChatListView { } } - func refreshDueToExternalTransaction(postbox: Postbox) -> Bool { + func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool { var updated = false self.state = ChatListViewState(postbox: postbox, spaces: self.spaces, anchorIndex: .absoluteUpperBound, summaryComponents: self.summaryComponents, halfLimit: self.count) @@ -469,7 +469,7 @@ final class MutableChatListView { return updated } - func replay(postbox: Postbox, operations: [PeerGroupId: [ChatListOperation]], updatedPeerNotificationSettings: [PeerId: (PeerNotificationSettings?, PeerNotificationSettings)], updatedPeers: [PeerId: Peer], updatedPeerPresences: [PeerId: PeerPresence], transaction: PostboxTransaction, context: MutableChatListViewReplayContext) -> Bool { + func replay(postbox: PostboxImpl, operations: [PeerGroupId: [ChatListOperation]], updatedPeerNotificationSettings: [PeerId: (PeerNotificationSettings?, PeerNotificationSettings)], updatedPeers: [PeerId: Peer], updatedPeerPresences: [PeerId: PeerPresence], transaction: PostboxTransaction, context: MutableChatListViewReplayContext) -> Bool { var hasChanges = false if transaction.updatedGlobalNotificationSettings && self.filterPredicate != nil { @@ -551,7 +551,7 @@ final class MutableChatListView { return hasChanges } - func complete(postbox: Postbox, context: MutableChatListViewReplayContext) { + func complete(postbox: PostboxImpl, context: MutableChatListViewReplayContext) { } @@ -559,7 +559,7 @@ final class MutableChatListView { return self.sampledState.hole } - private func renderEntry(_ entry: MutableChatListEntry, postbox: Postbox) -> MutableChatListEntry? { + private func renderEntry(_ entry: MutableChatListEntry, postbox: PostboxImpl) -> MutableChatListEntry? { switch entry { case let .IntermediateMessageEntry(index, messageIndex): var renderedMessages: [Message] = [] @@ -597,7 +597,7 @@ final class MutableChatListView { } } - func render(postbox: Postbox) { + func render(postbox: PostboxImpl) { for i in 0 ..< self.additionalItemEntries.count { if let updatedEntry = self.renderEntry(self.additionalItemEntries[i].entry, postbox: postbox) { self.additionalItemEntries[i].entry = updatedEntry diff --git a/submodules/Postbox/Sources/ChatListViewState.swift b/submodules/Postbox/Sources/ChatListViewState.swift index 02b160bae6..9f17877761 100644 --- a/submodules/Postbox/Sources/ChatListViewState.swift +++ b/submodules/Postbox/Sources/ChatListViewState.swift @@ -53,7 +53,7 @@ enum ChatListViewSpace: Hashable { } } -private func mappedChatListFilterPredicate(postbox: Postbox, groupId: PeerGroupId, predicate: ChatListFilterPredicate) -> (ChatListIntermediateEntry) -> Bool { +private func mappedChatListFilterPredicate(postbox: PostboxImpl, groupId: PeerGroupId, predicate: ChatListFilterPredicate) -> (ChatListIntermediateEntry) -> Bool { let globalNotificationSettings = postbox.getGlobalNotificationSettings() return { entry in switch entry { @@ -131,7 +131,7 @@ private final class ChatListViewSpaceState { var orderedEntries: OrderedChatListViewEntries - init(postbox: Postbox, space: ChatListViewSpace, anchorIndex: MutableChatListEntryIndex, summaryComponents: ChatListEntrySummaryComponents, halfLimit: Int) { + init(postbox: PostboxImpl, space: ChatListViewSpace, anchorIndex: MutableChatListEntryIndex, summaryComponents: ChatListEntrySummaryComponents, halfLimit: Int) { self.space = space self.anchorIndex = anchorIndex self.summaryComponents = summaryComponents @@ -142,7 +142,7 @@ private final class ChatListViewSpaceState { self.checkEntries(postbox: postbox) } - private func fillSpace(postbox: Postbox) { + private func fillSpace(postbox: PostboxImpl) { switch self.space { case let .group(groupId, pinned, filterPredicate): let lowerBound: MutableChatListEntryIndex @@ -370,7 +370,7 @@ private final class ChatListViewSpaceState { assert(self.orderedEntries.higherThanAnchor.count <= self.halfLimit) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var hasUpdates = false var hadRemovals = false var globalNotificationSettings: PostboxGlobalNotificationSettings? @@ -850,7 +850,7 @@ private final class ChatListViewSpaceState { return hasUpdates } - private func checkEntries(postbox: Postbox) { + private func checkEntries(postbox: PostboxImpl) { #if DEBUG if case .group(.root, .notPinned, nil) = self.space { let allEntries = self.orderedEntries.lowerOrAtAnchor + self.orderedEntries.higherThanAnchor @@ -874,7 +874,7 @@ private final class ChatListViewSpaceState { #endif } - private func checkReplayEntries(postbox: Postbox) { + private func checkReplayEntries(postbox: PostboxImpl) { #if DEBUG let cleanState = ChatListViewSpaceState(postbox: postbox, space: self.space, anchorIndex: self.anchorIndex, summaryComponents: self.summaryComponents, halfLimit: self.halfLimit) //assert(self.orderedEntries.lowerOrAtAnchor.map { $0.index } == cleanState.orderedEntries.lowerOrAtAnchor.map { $0.index }) @@ -1218,7 +1218,7 @@ struct ChatListViewState { private let halfLimit: Int private var stateBySpace: [ChatListViewSpace: ChatListViewSpaceState] = [:] - init(postbox: Postbox, spaces: [ChatListViewSpace], anchorIndex: ChatListIndex, summaryComponents: ChatListEntrySummaryComponents, halfLimit: Int) { + init(postbox: PostboxImpl, spaces: [ChatListViewSpace], anchorIndex: ChatListIndex, summaryComponents: ChatListEntrySummaryComponents, halfLimit: Int) { self.anchorIndex = MutableChatListEntryIndex(index: anchorIndex, isMessage: true) self.summaryComponents = summaryComponents self.halfLimit = halfLimit @@ -1228,7 +1228,7 @@ struct ChatListViewState { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for (_, state) in self.stateBySpace { if state.replay(postbox: postbox, transaction: transaction) { @@ -1314,7 +1314,7 @@ struct ChatListViewState { return (backwardsResult.reversed(), result) } - func sample(postbox: Postbox) -> ChatListViewSample { + func sample(postbox: PostboxImpl) -> ChatListViewSample { let combinedSpacesAndIndicesByDirection = self.sampleIndices() var result: [(ChatListViewSpace, MutableChatListEntry)] = [] diff --git a/submodules/Postbox/Sources/ContactPeersView.swift b/submodules/Postbox/Sources/ContactPeersView.swift index 3cbf0fe0a2..dc9ea70ec3 100644 --- a/submodules/Postbox/Sources/ContactPeersView.swift +++ b/submodules/Postbox/Sources/ContactPeersView.swift @@ -15,7 +15,7 @@ final class MutableContactPeersView { self.includePresences = includePresences } - func replay(postbox: Postbox, replacePeerIds: Set?, updatedPeerPresences: [PeerId: PeerPresence]) -> Bool { + func replay(postbox: PostboxImpl, replacePeerIds: Set?, updatedPeerPresences: [PeerId: PeerPresence]) -> Bool { var updated = false if let replacePeerIds = replacePeerIds { let removedPeerIds = self.peerIds.subtracting(replacePeerIds) diff --git a/submodules/Postbox/Sources/FailedMessagesView.swift b/submodules/Postbox/Sources/FailedMessagesView.swift index 1a1105f41e..df2dbee92c 100644 --- a/submodules/Postbox/Sources/FailedMessagesView.swift +++ b/submodules/Postbox/Sources/FailedMessagesView.swift @@ -6,7 +6,7 @@ final class MutableFailedMessageIdsView { self.peerId = peerId self.ids = Set(ids) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { let ids = transaction.updatedFailedMessageIds.filter { $0.peerId == self.peerId } let updated = ids != self.ids self.ids = ids diff --git a/submodules/Postbox/Sources/GlobalMessageTagsView.swift b/submodules/Postbox/Sources/GlobalMessageTagsView.swift index 7e272d24f1..941f6c8096 100644 --- a/submodules/Postbox/Sources/GlobalMessageTagsView.swift +++ b/submodules/Postbox/Sources/GlobalMessageTagsView.swift @@ -90,7 +90,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView { fileprivate var earlier: MessageIndex? fileprivate var later: MessageIndex? - init(postbox: Postbox, globalTag: GlobalMessageTags, position: MessageIndex, count: Int, groupingPredicate: ((Message, Message) -> Bool)?) { + init(postbox: PostboxImpl, globalTag: GlobalMessageTags, position: MessageIndex, count: Int, groupingPredicate: ((Message, Message) -> Bool)?) { self.globalTag = globalTag self.position = position self.count = count @@ -112,7 +112,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView { self.render(postbox: postbox) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var hasChanges = false let context = MutableGlobalMessageTagsViewReplayContext() @@ -291,7 +291,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView { return hasChanges } - private func complete(postbox: Postbox, context: MutableGlobalMessageTagsViewReplayContext) { + private func complete(postbox: PostboxImpl, context: MutableGlobalMessageTagsViewReplayContext) { if context.removedEntries { self.completeWithReset(postbox: postbox) } else { @@ -333,7 +333,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView { } } - private func completeWithReset(postbox: Postbox) { + private func completeWithReset(postbox: PostboxImpl) { var addedEntries: [InternalGlobalMessageTagsEntry] = [] var latestAnchor: MessageIndex? @@ -453,7 +453,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView { } } - private func render(postbox: Postbox) { + private func render(postbox: PostboxImpl) { for i in 0 ..< self.entries.count { if case let .intermediateMessage(message) = self.entries[i] { self.entries[i] = .message(postbox.renderIntermediateMessage(message)) diff --git a/submodules/Postbox/Sources/HistoryTagInfoView.swift b/submodules/Postbox/Sources/HistoryTagInfoView.swift index 4b145600b2..d3bd9de9a6 100644 --- a/submodules/Postbox/Sources/HistoryTagInfoView.swift +++ b/submodules/Postbox/Sources/HistoryTagInfoView.swift @@ -6,7 +6,7 @@ final class MutableHistoryTagInfoView: MutablePostboxView { fileprivate var currentIndex: MessageIndex? - init(postbox: Postbox, peerId: PeerId, tag: MessageTags) { + init(postbox: PostboxImpl, peerId: PeerId, tag: MessageTags) { self.peerId = peerId self.tag = tag for namespace in postbox.messageHistoryIndexTable.existingNamespaces(peerId: self.peerId) { @@ -17,7 +17,7 @@ final class MutableHistoryTagInfoView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if let operations = transaction.currentOperationsByPeerId[self.peerId] { var updated = false var refresh = false diff --git a/submodules/Postbox/Sources/InvalidatedMessageHistoryTagSummariesView.swift b/submodules/Postbox/Sources/InvalidatedMessageHistoryTagSummariesView.swift index 2b15af51f1..7e082850ff 100644 --- a/submodules/Postbox/Sources/InvalidatedMessageHistoryTagSummariesView.swift +++ b/submodules/Postbox/Sources/InvalidatedMessageHistoryTagSummariesView.swift @@ -5,7 +5,7 @@ final class MutableInvalidatedMessageHistoryTagSummariesView: MutablePostboxView var entries = Set() - init(postbox: Postbox, tagMask: MessageTags, namespace: MessageId.Namespace) { + init(postbox: PostboxImpl, tagMask: MessageTags, namespace: MessageId.Namespace) { self.tagMask = tagMask self.namespace = namespace @@ -14,7 +14,7 @@ final class MutableInvalidatedMessageHistoryTagSummariesView: MutablePostboxView } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for operation in transaction.currentInvalidateMessageTagSummaries { switch operation { diff --git a/submodules/Postbox/Sources/ItemCollectionIdsView.swift b/submodules/Postbox/Sources/ItemCollectionIdsView.swift index cde4e4b6d8..fed265431f 100644 --- a/submodules/Postbox/Sources/ItemCollectionIdsView.swift +++ b/submodules/Postbox/Sources/ItemCollectionIdsView.swift @@ -4,7 +4,7 @@ final class MutableItemCollectionIdsView: MutablePostboxView { let namespaces: [ItemCollectionId.Namespace] var idsByNamespace: [ItemCollectionId.Namespace: Set] - init(postbox: Postbox, namespaces: [ItemCollectionId.Namespace]) { + init(postbox: PostboxImpl, namespaces: [ItemCollectionId.Namespace]) { self.namespaces = namespaces var idsByNamespace: [ItemCollectionId.Namespace: Set] = [:] @@ -15,7 +15,7 @@ final class MutableItemCollectionIdsView: MutablePostboxView { self.idsByNamespace = idsByNamespace } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if transaction.currentItemCollectionInfosOperations.isEmpty { return false } diff --git a/submodules/Postbox/Sources/ItemCollectionInfoView.swift b/submodules/Postbox/Sources/ItemCollectionInfoView.swift index 63f70b0ae4..7ce6008419 100644 --- a/submodules/Postbox/Sources/ItemCollectionInfoView.swift +++ b/submodules/Postbox/Sources/ItemCollectionInfoView.swift @@ -4,7 +4,7 @@ final class MutableItemCollectionInfoView: MutablePostboxView { let id: ItemCollectionId var info: ItemCollectionInfo? - init(postbox: Postbox, id: ItemCollectionId) { + init(postbox: PostboxImpl, id: ItemCollectionId) { self.id = id let infos = postbox.itemCollectionInfoTable.getInfos(namespace: id.namespace) for (_, infoId, info) in infos { @@ -15,7 +15,7 @@ final class MutableItemCollectionInfoView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if transaction.currentItemCollectionInfosOperations.isEmpty { return false } diff --git a/submodules/Postbox/Sources/ItemCollectionInfosView.swift b/submodules/Postbox/Sources/ItemCollectionInfosView.swift index e95b1ff156..d82b6af593 100644 --- a/submodules/Postbox/Sources/ItemCollectionInfosView.swift +++ b/submodules/Postbox/Sources/ItemCollectionInfosView.swift @@ -18,7 +18,7 @@ final class MutableItemCollectionInfosView: MutablePostboxView { let namespaces: [ItemCollectionId.Namespace] var entriesByNamespace: [ItemCollectionId.Namespace: [ItemCollectionInfoEntry]] - init(postbox: Postbox, namespaces: [ItemCollectionId.Namespace]) { + init(postbox: PostboxImpl, namespaces: [ItemCollectionId.Namespace]) { self.namespaces = namespaces var entriesByNamespace: [ItemCollectionId.Namespace: [ItemCollectionInfoEntry]] = [:] @@ -34,7 +34,7 @@ final class MutableItemCollectionInfosView: MutablePostboxView { self.entriesByNamespace = entriesByNamespace } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if transaction.currentItemCollectionInfosOperations.isEmpty && transaction.currentItemCollectionItemsOperations.isEmpty { return false } diff --git a/submodules/Postbox/Sources/ItemCollectionsView.swift b/submodules/Postbox/Sources/ItemCollectionsView.swift index 8db3adad4e..2566df1e00 100644 --- a/submodules/Postbox/Sources/ItemCollectionsView.swift +++ b/submodules/Postbox/Sources/ItemCollectionsView.swift @@ -179,7 +179,7 @@ final class MutableItemCollectionsView { var lower: ItemCollectionViewEntry? var higher: ItemCollectionViewEntry? - init(postbox: Postbox, orderedItemListsViews: [MutableOrderedItemListView], namespaces: [ItemCollectionId.Namespace], aroundIndex: ItemCollectionViewEntryIndex?, count: Int) { + init(postbox: PostboxImpl, orderedItemListsViews: [MutableOrderedItemListView], namespaces: [ItemCollectionId.Namespace], aroundIndex: ItemCollectionViewEntryIndex?, count: Int) { self.orderedItemListsViews = orderedItemListsViews self.namespaces = namespaces self.requestedAroundIndex = aroundIndex @@ -193,23 +193,23 @@ final class MutableItemCollectionsView { self.reload(postbox: postbox, aroundIndex: aroundIndex, count: count) } - private func lowerItems(postbox: Postbox, collectionId: ItemCollectionId, itemIndex: ItemCollectionItemIndex, count: Int) -> [ItemCollectionItem] { + private func lowerItems(postbox: PostboxImpl, collectionId: ItemCollectionId, itemIndex: ItemCollectionItemIndex, count: Int) -> [ItemCollectionItem] { return postbox.itemCollectionItemTable.lowerItems(collectionId: collectionId, itemIndex: itemIndex, count: count) } - private func higherItems(postbox: Postbox, collectionId: ItemCollectionId, itemIndex: ItemCollectionItemIndex, count: Int) -> [ItemCollectionItem] { + private func higherItems(postbox: PostboxImpl, collectionId: ItemCollectionId, itemIndex: ItemCollectionItemIndex, count: Int) -> [ItemCollectionItem] { return postbox.itemCollectionItemTable.higherItems(collectionId: collectionId, itemIndex: itemIndex, count: count) } - private func lowerCollectionId(postbox: Postbox, namespaceList: [ItemCollectionId.Namespace], collectionId: ItemCollectionId, collectionIndex: Int32) -> (ItemCollectionId, Int32)? { + private func lowerCollectionId(postbox: PostboxImpl, namespaceList: [ItemCollectionId.Namespace], collectionId: ItemCollectionId, collectionIndex: Int32) -> (ItemCollectionId, Int32)? { return postbox.itemCollectionInfoTable.lowerCollectionId(namespaceList: namespaceList, collectionId: collectionId, index: collectionIndex) } - private func higherCollectionId(postbox: Postbox, namespaceList: [ItemCollectionId.Namespace], collectionId: ItemCollectionId, collectionIndex: Int32) -> (ItemCollectionId, Int32)? { + private func higherCollectionId(postbox: PostboxImpl, namespaceList: [ItemCollectionId.Namespace], collectionId: ItemCollectionId, collectionIndex: Int32) -> (ItemCollectionId, Int32)? { return postbox.itemCollectionInfoTable.higherCollectionId(namespaceList: namespaceList, collectionId: collectionId, index: collectionIndex) } - private func reload(postbox: Postbox, aroundIndex: ItemCollectionViewEntryIndex?, count: Int) { + private func reload(postbox: PostboxImpl, aroundIndex: ItemCollectionViewEntryIndex?, count: Int) { self.collectionInfos = [] for namespace in namespaces { for (_, id, info) in postbox.itemCollectionInfoTable.getInfos(namespace: namespace) { @@ -242,7 +242,7 @@ final class MutableItemCollectionsView { self.higher = higher } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if !transaction.currentOrderedItemListOperations.isEmpty { diff --git a/submodules/Postbox/Sources/LocalMessageTagsView.swift b/submodules/Postbox/Sources/LocalMessageTagsView.swift index d409e3ba51..356f6c8efb 100644 --- a/submodules/Postbox/Sources/LocalMessageTagsView.swift +++ b/submodules/Postbox/Sources/LocalMessageTagsView.swift @@ -4,7 +4,7 @@ final class MutableLocalMessageTagsView: MutablePostboxView { private let tag: LocalMessageTags fileprivate var messages: [MessageId: Message] = [:] - init(postbox: Postbox, tag: LocalMessageTags) { + init(postbox: PostboxImpl, tag: LocalMessageTags) { self.tag = tag for id in postbox.localMessageHistoryTagsTable.get(tag: tag) { if let message = postbox.getMessage(id) { @@ -15,7 +15,7 @@ final class MutableLocalMessageTagsView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for operation in transaction.currentLocalTagsOperations { switch operation { diff --git a/submodules/Postbox/Sources/MessageHistoryReadStateTable.swift b/submodules/Postbox/Sources/MessageHistoryReadStateTable.swift index 15f2fb9af5..6549ee3261 100644 --- a/submodules/Postbox/Sources/MessageHistoryReadStateTable.swift +++ b/submodules/Postbox/Sources/MessageHistoryReadStateTable.swift @@ -380,7 +380,7 @@ final class MessageHistoryReadStateTable: Table { return (nil, false, []) } - func applyInteractiveMaxReadIndex(postbox: Postbox, messageIndex: MessageIndex, incomingStatsInRange: (MessageId.Namespace, MessageId.Id, MessageId.Id) -> (count: Int, holes: Bool), incomingIndexStatsInRange: (MessageIndex, MessageIndex) -> (count: Int, holes: Bool, readMesageIds: [MessageId]), topMessageId: (MessageId.Id, Bool)?, topMessageIndexByNamespace: (MessageId.Namespace) -> MessageIndex?) -> (combinedState: CombinedPeerReadState?, ApplyInteractiveMaxReadIdResult, readMesageIds: [MessageId]) { + func applyInteractiveMaxReadIndex(postbox: PostboxImpl, messageIndex: MessageIndex, incomingStatsInRange: (MessageId.Namespace, MessageId.Id, MessageId.Id) -> (count: Int, holes: Bool), incomingIndexStatsInRange: (MessageIndex, MessageIndex) -> (count: Int, holes: Bool, readMesageIds: [MessageId]), topMessageId: (MessageId.Id, Bool)?, topMessageIndexByNamespace: (MessageId.Namespace) -> MessageIndex?) -> (combinedState: CombinedPeerReadState?, ApplyInteractiveMaxReadIdResult, readMesageIds: [MessageId]) { if let states = self.get(messageIndex.id.peerId) { if let state = states.namespaces[messageIndex.id.namespace] { switch state { diff --git a/submodules/Postbox/Sources/MessageHistoryTable.swift b/submodules/Postbox/Sources/MessageHistoryTable.swift index 35f7affa81..718ba73129 100644 --- a/submodules/Postbox/Sources/MessageHistoryTable.swift +++ b/submodules/Postbox/Sources/MessageHistoryTable.swift @@ -624,7 +624,7 @@ final class MessageHistoryTable: Table { return messageIds } - func applyInteractiveMaxReadIndex(postbox: Postbox, messageIndex: MessageIndex, operationsByPeerId: inout [PeerId: [MessageHistoryOperation]], updatedPeerReadStateOperations: inout [PeerId: PeerReadStateSynchronizationOperation?]) -> [MessageId] { + func applyInteractiveMaxReadIndex(postbox: PostboxImpl, messageIndex: MessageIndex, operationsByPeerId: inout [PeerId: [MessageHistoryOperation]], updatedPeerReadStateOperations: inout [PeerId: PeerReadStateSynchronizationOperation?]) -> [MessageId] { var topMessageId: (MessageId.Id, Bool)? if let index = self.topIndexEntry(peerId: messageIndex.id.peerId, namespace: messageIndex.id.namespace) { if let message = self.getMessage(index) { diff --git a/submodules/Postbox/Sources/MessageHistoryTagSummaryView.swift b/submodules/Postbox/Sources/MessageHistoryTagSummaryView.swift index 5ddfe28b2f..b56759162c 100644 --- a/submodules/Postbox/Sources/MessageHistoryTagSummaryView.swift +++ b/submodules/Postbox/Sources/MessageHistoryTagSummaryView.swift @@ -7,7 +7,7 @@ final class MutableMessageHistoryTagSummaryView: MutablePostboxView { fileprivate var count: Int32? - init(postbox: Postbox, tag: MessageTags, peerId: PeerId, namespace: MessageId.Namespace) { + init(postbox: PostboxImpl, tag: MessageTags, peerId: PeerId, namespace: MessageId.Namespace) { self.tag = tag self.peerId = peerId self.namespace = namespace @@ -15,7 +15,7 @@ final class MutableMessageHistoryTagSummaryView: MutablePostboxView { self.count = postbox.messageHistoryTagsSummaryTable.get(MessageHistoryTagsSummaryKey(tag: tag, peerId: peerId, namespace: namespace))?.count } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var hasChanges = false if let summary = transaction.currentUpdatedMessageTagSummaries[MessageHistoryTagsSummaryKey(tag: self.tag, peerId: self.peerId, namespace: self.namespace)] { diff --git a/submodules/Postbox/Sources/MessageHistoryView.swift b/submodules/Postbox/Sources/MessageHistoryView.swift index 4966a9dea8..7543827b81 100644 --- a/submodules/Postbox/Sources/MessageHistoryView.swift +++ b/submodules/Postbox/Sources/MessageHistoryView.swift @@ -332,7 +332,7 @@ final class MutableMessageHistoryView { fileprivate var isAddedToChatList: Bool - init(postbox: Postbox, orderStatistics: MessageHistoryViewOrderStatistics, clipHoles: Bool, peerIds: MessageHistoryViewInput, anchor inputAnchor: HistoryViewInputAnchor, combinedReadStates: MessageHistoryViewReadState?, transientReadStates: MessageHistoryViewReadState?, tag: MessageTags?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, count: Int, topTaggedMessages: [MessageId.Namespace: MessageHistoryTopTaggedMessage?], additionalDatas: [AdditionalMessageHistoryViewDataEntry], getMessageCountInRange: (MessageIndex, MessageIndex) -> Int32) { + init(postbox: PostboxImpl, orderStatistics: MessageHistoryViewOrderStatistics, clipHoles: Bool, peerIds: MessageHistoryViewInput, anchor inputAnchor: HistoryViewInputAnchor, combinedReadStates: MessageHistoryViewReadState?, transientReadStates: MessageHistoryViewReadState?, tag: MessageTags?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, count: Int, topTaggedMessages: [MessageId.Namespace: MessageHistoryTopTaggedMessage?], additionalDatas: [AdditionalMessageHistoryViewDataEntry], getMessageCountInRange: (MessageIndex, MessageIndex) -> Int32) { self.anchor = inputAnchor self.orderStatistics = orderStatistics @@ -372,7 +372,7 @@ final class MutableMessageHistoryView { self.render(postbox: postbox) } - private func reset(postbox: Postbox) { + private func reset(postbox: PostboxImpl) { self.state = HistoryViewState(postbox: postbox, inputAnchor: self.anchor, tag: self.tag, appendMessagesFromTheSameGroup: self.appendMessagesFromTheSameGroup, namespaces: self.namespaces, statistics: self.orderStatistics, halfLimit: self.fillCount + 1, locations: self.peerIds) if case let .loading(loadingState) = self.state { let sampledState = loadingState.checkAndSample(postbox: postbox) @@ -395,7 +395,7 @@ final class MutableMessageHistoryView { self.sampledState = self.state.sample(postbox: postbox, clipHoles: self.clipHoles) } - func refreshDueToExternalTransaction(postbox: Postbox) -> Bool { + func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool { self.reset(postbox: postbox) return true } @@ -419,7 +419,7 @@ final class MutableMessageHistoryView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var operations: [[MessageHistoryOperation]] = [] var holePeerIdsSet = Set() @@ -854,7 +854,7 @@ final class MutableMessageHistoryView { return hasChanges } - private func render(postbox: Postbox) { + private func render(postbox: PostboxImpl) { for namespace in self.topTaggedMessages.keys { if let entry = self.topTaggedMessages[namespace]!, case let .intermediate(message) = entry { let item: MessageHistoryTopTaggedMessage? = .message(postbox.messageHistoryTable.renderMessage(message, peerTable: postbox.peerTable)) diff --git a/submodules/Postbox/Sources/MessageHistoryViewState.swift b/submodules/Postbox/Sources/MessageHistoryViewState.swift index 7257692472..d0e40d65d6 100644 --- a/submodules/Postbox/Sources/MessageHistoryViewState.swift +++ b/submodules/Postbox/Sources/MessageHistoryViewState.swift @@ -25,7 +25,7 @@ public enum MessageHistoryInput: Equatable, Hashable { } private extension MessageHistoryInput { - func fetch(postbox: Postbox, peerId: PeerId, namespace: MessageId.Namespace, from fromIndex: MessageIndex, includeFrom: Bool, to toIndex: MessageIndex, limit: Int) -> [IntermediateMessage] { + func fetch(postbox: PostboxImpl, peerId: PeerId, namespace: MessageId.Namespace, from fromIndex: MessageIndex, includeFrom: Bool, to toIndex: MessageIndex, limit: Int) -> [IntermediateMessage] { switch self { case let .automatic(automatic): var items = postbox.messageHistoryTable.fetch(peerId: peerId, namespace: namespace, tag: automatic?.tag, threadId: nil, from: fromIndex, includeFrom: includeFrom, to: toIndex, limit: limit) @@ -74,7 +74,7 @@ private extension MessageHistoryInput { } } - func getMessageCountInRange(postbox: Postbox, peerId: PeerId, namespace: MessageId.Namespace, lowerBound: MessageIndex, upperBound: MessageIndex) -> Int { + func getMessageCountInRange(postbox: PostboxImpl, peerId: PeerId, namespace: MessageId.Namespace, lowerBound: MessageIndex, upperBound: MessageIndex) -> Int { switch self { case let .automatic(automatic): if let automatic = automatic { @@ -884,7 +884,7 @@ final class HistoryViewLoadedState { var holes: HistoryViewHoles var spacesWithRemovals = Set() - init(anchor: HistoryViewAnchor, tag: MessageTags?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, statistics: MessageHistoryViewOrderStatistics, halfLimit: Int, locations: MessageHistoryViewInput, postbox: Postbox, holes: HistoryViewHoles) { + init(anchor: HistoryViewAnchor, tag: MessageTags?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, statistics: MessageHistoryViewOrderStatistics, halfLimit: Int, locations: MessageHistoryViewInput, postbox: PostboxImpl, holes: HistoryViewHoles) { precondition(halfLimit >= 3) self.anchor = anchor self.namespaces = namespaces @@ -930,7 +930,7 @@ final class HistoryViewLoadedState { } } - private func fillSpace(space: PeerIdAndNamespace, postbox: Postbox) { + private func fillSpace(space: PeerIdAndNamespace, postbox: PostboxImpl) { let anchorIndex: MessageIndex let lowerBound = MessageIndex.lowerBound(peerId: space.peerId, namespace: space.namespace) let upperBound = MessageIndex.upperBound(peerId: space.peerId, namespace: space.namespace) @@ -1040,7 +1040,7 @@ final class HistoryViewLoadedState { return self.holes.removeHole(space: space, range: range) } - func updateTimestamp(postbox: Postbox, index: MessageIndex, timestamp: Int32) -> Bool { + func updateTimestamp(postbox: PostboxImpl, index: MessageIndex, timestamp: Int32) -> Bool { let space = PeerIdAndNamespace(peerId: index.id.peerId, namespace: index.id.namespace) if self.orderedEntriesBySpace[space] == nil { return false @@ -1274,7 +1274,7 @@ final class HistoryViewLoadedState { return updated } - func completeAndSample(postbox: Postbox, clipHoles: Bool) -> HistoryViewLoadedSample { + func completeAndSample(postbox: PostboxImpl, clipHoles: Bool) -> HistoryViewLoadedSample { if !self.spacesWithRemovals.isEmpty { for space in self.spacesWithRemovals { self.fillSpace(space: space, postbox: postbox) @@ -1364,7 +1364,7 @@ final class HistoryViewLoadedState { } } -private func fetchHoles(postbox: Postbox, locations: MessageHistoryViewInput, tag: MessageTags?, namespaces: MessageIdNamespaces) -> [PeerIdAndNamespace: IndexSet] { +private func fetchHoles(postbox: PostboxImpl, locations: MessageHistoryViewInput, tag: MessageTags?, namespaces: MessageIdNamespaces) -> [PeerIdAndNamespace: IndexSet] { var peerIds: [PeerId] = [] switch locations { case let .single(peerId): @@ -1425,7 +1425,7 @@ final class HistoryViewLoadingState { let halfLimit: Int var holes: HistoryViewHoles - init(postbox: Postbox, locations: MessageHistoryViewInput, tag: MessageTags?, threadId: Int64?, namespaces: MessageIdNamespaces, messageId: MessageId, halfLimit: Int) { + init(postbox: PostboxImpl, locations: MessageHistoryViewInput, tag: MessageTags?, threadId: Int64?, namespaces: MessageIdNamespaces, messageId: MessageId, halfLimit: Int) { self.messageId = messageId self.tag = tag self.threadId = threadId @@ -1441,7 +1441,7 @@ final class HistoryViewLoadingState { return self.holes.removeHole(space: space, range: range) } - func checkAndSample(postbox: Postbox) -> HistoryViewLoadingSample { + func checkAndSample(postbox: PostboxImpl) -> HistoryViewLoadingSample { while true { if let indices = self.holes.holesBySpace[PeerIdAndNamespace(peerId: self.messageId.peerId, namespace: self.messageId.namespace)] { if indices.contains(Int(messageId.id)) { @@ -1470,7 +1470,7 @@ enum HistoryViewState { case loaded(HistoryViewLoadedState) case loading(HistoryViewLoadingState) - init(postbox: Postbox, inputAnchor: HistoryViewInputAnchor, tag: MessageTags?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, statistics: MessageHistoryViewOrderStatistics, halfLimit: Int, locations: MessageHistoryViewInput) { + init(postbox: PostboxImpl, inputAnchor: HistoryViewInputAnchor, tag: MessageTags?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, statistics: MessageHistoryViewOrderStatistics, halfLimit: Int, locations: MessageHistoryViewInput) { switch inputAnchor { case let .index(index): self = .loaded(HistoryViewLoadedState(anchor: .index(index), tag: tag, appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, namespaces: namespaces, statistics: statistics, halfLimit: halfLimit, locations: locations, postbox: postbox, holes: HistoryViewHoles(holesBySpace: fetchHoles(postbox: postbox, locations: locations, tag: tag, namespaces: namespaces)))) @@ -1546,7 +1546,7 @@ enum HistoryViewState { } } - func sample(postbox: Postbox, clipHoles: Bool) -> HistoryViewSample { + func sample(postbox: PostboxImpl, clipHoles: Bool) -> HistoryViewSample { switch self { case let .loading(loadingState): return .loading(loadingState.checkAndSample(postbox: postbox)) diff --git a/submodules/Postbox/Sources/MessageOfInterestHolesView.swift b/submodules/Postbox/Sources/MessageOfInterestHolesView.swift index 21a4b298d8..9b7f3b43af 100644 --- a/submodules/Postbox/Sources/MessageOfInterestHolesView.swift +++ b/submodules/Postbox/Sources/MessageOfInterestHolesView.swift @@ -38,7 +38,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView { fileprivate var closestHole: MessageOfInterestHole? fileprivate var closestLaterMedia: [HolesViewMedia] = [] - init(postbox: Postbox, location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int) { + init(postbox: PostboxImpl, location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int) { self.location = location self.count = count @@ -105,7 +105,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var peerId: PeerId switch self.location { case let .peer(id): diff --git a/submodules/Postbox/Sources/MessageView.swift b/submodules/Postbox/Sources/MessageView.swift index 3bbd9a8e66..1ae3ed291f 100644 --- a/submodules/Postbox/Sources/MessageView.swift +++ b/submodules/Postbox/Sources/MessageView.swift @@ -11,7 +11,7 @@ final class MutableMessageView { self.stableId = message?.stableId } - func replay(postbox: Postbox, operations: [MessageHistoryOperation], updatedMedia: [MediaId: Media?]) -> Bool { + func replay(postbox: PostboxImpl, operations: [MessageHistoryOperation], updatedMedia: [MediaId: Media?]) -> Bool { var updated = false for operation in operations { switch operation { diff --git a/submodules/Postbox/Sources/MessagesView.swift b/submodules/Postbox/Sources/MessagesView.swift index d54372f5ad..ae4a1b4d94 100644 --- a/submodules/Postbox/Sources/MessagesView.swift +++ b/submodules/Postbox/Sources/MessagesView.swift @@ -5,7 +5,7 @@ final class MutableMessagesView: MutablePostboxView { private let peerIds: Set fileprivate var messages: [MessageId: Message] = [:] - init(postbox: Postbox, ids: Set) { + init(postbox: PostboxImpl, ids: Set) { self.ids = ids self.peerIds = Set(ids.map { $0.peerId }) for id in ids { @@ -15,7 +15,7 @@ final class MutableMessagesView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updatedIds = Set() for peerId in self.peerIds { if let operations = transaction.currentOperationsByPeerId[peerId] { diff --git a/submodules/Postbox/Sources/MutableBasicPeerView.swift b/submodules/Postbox/Sources/MutableBasicPeerView.swift index db8f3b1b74..a2f30f8f6b 100644 --- a/submodules/Postbox/Sources/MutableBasicPeerView.swift +++ b/submodules/Postbox/Sources/MutableBasicPeerView.swift @@ -7,7 +7,7 @@ final class MutableBasicPeerView: MutablePostboxView { fileprivate var isContact: Bool fileprivate var groupId: PeerGroupId? - init(postbox: Postbox, peerId: PeerId) { + init(postbox: PostboxImpl, peerId: PeerId) { self.peerId = peerId self.peer = postbox.peerTable.get(peerId) self.notificationSettings = postbox.peerNotificationSettingsTable.getEffective(peerId) @@ -15,7 +15,7 @@ final class MutableBasicPeerView: MutablePostboxView { self.groupId = postbox.chatListIndexTable.get(peerId: peerId).inclusion.groupId } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if let peer = transaction.currentUpdatedPeers[self.peerId] { self.peer = peer diff --git a/submodules/Postbox/Sources/MutablePeerChatInclusionView.swift b/submodules/Postbox/Sources/MutablePeerChatInclusionView.swift index 1b72a9233d..9b7d5d1952 100644 --- a/submodules/Postbox/Sources/MutablePeerChatInclusionView.swift +++ b/submodules/Postbox/Sources/MutablePeerChatInclusionView.swift @@ -4,13 +4,13 @@ final class MutablePeerChatInclusionView: MutablePostboxView { private let peerId: PeerId fileprivate var inclusion: Bool - init(postbox: Postbox, peerId: PeerId) { + init(postbox: PostboxImpl, peerId: PeerId) { self.peerId = peerId self.inclusion = postbox.chatListIndexTable.get(peerId: self.peerId).includedIndex(peerId: peerId) != nil } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if transaction.currentUpdatedChatListInclusions[self.peerId] != nil { let inclusion = postbox.chatListIndexTable.get(peerId: self.peerId).includedIndex(peerId: self.peerId) != nil diff --git a/submodules/Postbox/Sources/OrderedItemListView.swift b/submodules/Postbox/Sources/OrderedItemListView.swift index c4f080603b..bdd066a8fc 100644 --- a/submodules/Postbox/Sources/OrderedItemListView.swift +++ b/submodules/Postbox/Sources/OrderedItemListView.swift @@ -4,12 +4,12 @@ final class MutableOrderedItemListView: MutablePostboxView { let collectionId: Int32 var items: [OrderedItemListEntry] - init(postbox: Postbox, collectionId: Int32) { + init(postbox: PostboxImpl, collectionId: Int32) { self.collectionId = collectionId self.items = postbox.orderedItemListTable.getItems(collectionId: collectionId) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if let operations = transaction.currentOrderedItemListOperations[self.collectionId] { diff --git a/submodules/Postbox/Sources/PeerChatStateView.swift b/submodules/Postbox/Sources/PeerChatStateView.swift index df1664653a..3c0edec8d6 100644 --- a/submodules/Postbox/Sources/PeerChatStateView.swift +++ b/submodules/Postbox/Sources/PeerChatStateView.swift @@ -4,12 +4,12 @@ final class MutablePeerChatStateView: MutablePostboxView { let peerId: PeerId var chatState: PostboxCoding? - init(postbox: Postbox, peerId: PeerId) { + init(postbox: PostboxImpl, peerId: PeerId) { self.peerId = peerId self.chatState = postbox.peerChatStateTable.get(peerId) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if transaction.currentUpdatedPeerChatStates.contains(self.peerId) { self.chatState = postbox.peerChatStateTable.get(self.peerId) return true diff --git a/submodules/Postbox/Sources/PeerMergedOperationLogView.swift b/submodules/Postbox/Sources/PeerMergedOperationLogView.swift index 01bfcf965d..af2daac0f6 100644 --- a/submodules/Postbox/Sources/PeerMergedOperationLogView.swift +++ b/submodules/Postbox/Sources/PeerMergedOperationLogView.swift @@ -6,14 +6,14 @@ final class MutablePeerMergedOperationLogView { var tailIndex: Int32? let limit: Int - init(postbox: Postbox, tag: PeerOperationLogTag, limit: Int) { + init(postbox: PostboxImpl, tag: PeerOperationLogTag, limit: Int) { self.tag = tag self.entries = postbox.peerOperationLogTable.getMergedEntries(tag: tag, fromIndex: 0, limit: limit) self.tailIndex = postbox.peerMergedOperationLogIndexTable.tailIndex(tag: tag) self.limit = limit } - func replay(postbox: Postbox, operations: [PeerMergedOperationLogOperation]) -> Bool { + func replay(postbox: PostboxImpl, operations: [PeerMergedOperationLogOperation]) -> Bool { var updated = false var invalidatedTail = false diff --git a/submodules/Postbox/Sources/PeerNotificationSettingsBehaviorTimestampView.swift b/submodules/Postbox/Sources/PeerNotificationSettingsBehaviorTimestampView.swift index 37df50df54..dd6448f5b8 100644 --- a/submodules/Postbox/Sources/PeerNotificationSettingsBehaviorTimestampView.swift +++ b/submodules/Postbox/Sources/PeerNotificationSettingsBehaviorTimestampView.swift @@ -3,11 +3,11 @@ import Foundation final class MutablePeerNotificationSettingsBehaviorTimestampView: MutablePostboxView { fileprivate var earliestTimestamp: Int32? - init(postbox: Postbox) { + init(postbox: PostboxImpl) { self.earliestTimestamp = postbox.peerNotificationSettingsBehaviorTable.getEarliest()?.1 } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if !transaction.currentUpdatedPeerNotificationBehaviorTimestamps.isEmpty { let earliestTimestamp = postbox.peerNotificationSettingsBehaviorTable.getEarliest()?.1 diff --git a/submodules/Postbox/Sources/PeerNotificationSettingsTable.swift b/submodules/Postbox/Sources/PeerNotificationSettingsTable.swift index 2f751e78a2..85a716419b 100644 --- a/submodules/Postbox/Sources/PeerNotificationSettingsTable.swift +++ b/submodules/Postbox/Sources/PeerNotificationSettingsTable.swift @@ -195,7 +195,7 @@ final class PeerNotificationSettingsTable: Table { self.updatedInitialSettings.removeAll() } - func transactionParticipationInTotalUnreadCountUpdates(postbox: Postbox) -> (added: Set, removed: Set) { + func transactionParticipationInTotalUnreadCountUpdates(postbox: PostboxImpl) -> (added: Set, removed: Set) { var added = Set() var removed = Set() diff --git a/submodules/Postbox/Sources/PeerNotificationSettingsView.swift b/submodules/Postbox/Sources/PeerNotificationSettingsView.swift index 22a0825d02..a1521e17a0 100644 --- a/submodules/Postbox/Sources/PeerNotificationSettingsView.swift +++ b/submodules/Postbox/Sources/PeerNotificationSettingsView.swift @@ -4,7 +4,7 @@ final class MutablePeerNotificationSettingsView: MutablePostboxView { let peerIds: Set var notificationSettings: [PeerId: PeerNotificationSettings] - init(postbox: Postbox, peerIds: Set) { + init(postbox: PostboxImpl, peerIds: Set) { self.peerIds = peerIds self.notificationSettings = [:] for peerId in peerIds { @@ -18,7 +18,7 @@ final class MutablePeerNotificationSettingsView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { if !transaction.currentUpdatedPeerNotificationSettings.isEmpty { var updated = false for peerId in self.peerIds { diff --git a/submodules/Postbox/Sources/PeerPresencesView.swift b/submodules/Postbox/Sources/PeerPresencesView.swift index d09bd71f30..4f280d944b 100644 --- a/submodules/Postbox/Sources/PeerPresencesView.swift +++ b/submodules/Postbox/Sources/PeerPresencesView.swift @@ -4,7 +4,7 @@ final class MutablePeerPresencesView: MutablePostboxView { fileprivate let ids: Set fileprivate var presences: [PeerId: PeerPresence] = [:] - init(postbox: Postbox, ids: Set) { + init(postbox: PostboxImpl, ids: Set) { self.ids = ids for id in ids { if let presence = postbox.peerPresenceTable.get(id) { @@ -13,7 +13,7 @@ final class MutablePeerPresencesView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if !transaction.currentUpdatedPeerPresences.isEmpty { for (id, presence) in transaction.currentUpdatedPeerPresences { diff --git a/submodules/Postbox/Sources/PeerView.swift b/submodules/Postbox/Sources/PeerView.swift index 0c5d610e2f..9fb5046de6 100644 --- a/submodules/Postbox/Sources/PeerView.swift +++ b/submodules/Postbox/Sources/PeerView.swift @@ -27,7 +27,7 @@ final class MutablePeerView: MutablePostboxView { var peerIsContact: Bool var groupId: PeerGroupId? - init(postbox: Postbox, peerId: PeerId, components: PeerViewComponents) { + init(postbox: PostboxImpl, peerId: PeerId, components: PeerViewComponents) { self.components = components let getPeer: (PeerId) -> Peer? = { peerId in @@ -83,11 +83,11 @@ final class MutablePeerView: MutablePostboxView { } } - func reset(postbox: Postbox) -> Bool { + func reset(postbox: PostboxImpl) -> Bool { return false } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { let updatedPeers = transaction.currentUpdatedPeers let updatedNotificationSettings = transaction.currentUpdatedPeerNotificationSettings let updatedCachedPeerData = transaction.currentUpdatedCachedPeerData diff --git a/submodules/Postbox/Sources/PendingMessageActionsSummaryView.swift b/submodules/Postbox/Sources/PendingMessageActionsSummaryView.swift index db57dcac70..dbfa7c7e56 100644 --- a/submodules/Postbox/Sources/PendingMessageActionsSummaryView.swift +++ b/submodules/Postbox/Sources/PendingMessageActionsSummaryView.swift @@ -3,12 +3,12 @@ final class MutablePendingMessageActionsSummaryView: MutablePostboxView { let key: PendingMessageActionsSummaryKey var count: Int32 - init(postbox: Postbox, type: PendingMessageActionType, peerId: PeerId, namespace: MessageId.Namespace) { + init(postbox: PostboxImpl, type: PendingMessageActionType, peerId: PeerId, namespace: MessageId.Namespace) { self.key = PendingMessageActionsSummaryKey(type: type, peerId: peerId, namespace: namespace) self.count = postbox.pendingMessageActionsMetadataTable.getCount(.peerNamespaceAction(peerId, namespace, type)) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if let updatedCount = transaction.currentUpdatedMessageActionsSummaries[self.key] { updated = true diff --git a/submodules/Postbox/Sources/PendingMessageActionsView.swift b/submodules/Postbox/Sources/PendingMessageActionsView.swift index 8d06de3210..87662edaef 100644 --- a/submodules/Postbox/Sources/PendingMessageActionsView.swift +++ b/submodules/Postbox/Sources/PendingMessageActionsView.swift @@ -3,12 +3,12 @@ final class MutablePendingMessageActionsView: MutablePostboxView { let type: PendingMessageActionType var entries: [PendingMessageActionsEntry] - init(postbox: Postbox, type: PendingMessageActionType) { + init(postbox: PostboxImpl, type: PendingMessageActionType) { self.type = type self.entries = postbox.pendingMessageActionsTable.getActions(type: type) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for operation in transaction.currentPendingMessageActionsOperations { switch operation { diff --git a/submodules/Postbox/Sources/PendingPeerNotificationSettingsView.swift b/submodules/Postbox/Sources/PendingPeerNotificationSettingsView.swift index cf794b2c8d..dfc7e22d22 100644 --- a/submodules/Postbox/Sources/PendingPeerNotificationSettingsView.swift +++ b/submodules/Postbox/Sources/PendingPeerNotificationSettingsView.swift @@ -2,7 +2,7 @@ final class MutablePendingPeerNotificationSettingsView: MutablePostboxView { var entries: [PeerId: PeerNotificationSettings] = [:] - init(postbox: Postbox) { + init(postbox: PostboxImpl) { for peerId in postbox.pendingPeerNotificationSettingsIndexTable.getAll() { if let value = postbox.peerNotificationSettingsTable.getPending(peerId) { self.entries[peerId] = value @@ -12,7 +12,7 @@ final class MutablePendingPeerNotificationSettingsView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for peerId in transaction.currentUpdatedPendingPeerNotificationSettings { if let value = postbox.peerNotificationSettingsTable.getPending(peerId) { diff --git a/submodules/Postbox/Sources/Postbox.swift b/submodules/Postbox/Sources/Postbox.swift index d1fd4d73fa..1cb33054a4 100644 --- a/submodules/Postbox/Sources/Postbox.swift +++ b/submodules/Postbox/Sources/Postbox.swift @@ -12,14 +12,20 @@ public enum PostboxUpdateMessage { } public final class Transaction { - private weak var postbox: Postbox? + private let queue: Queue + private weak var postbox: PostboxImpl? var disposed = false - fileprivate init(postbox: Postbox) { + fileprivate init(queue: Queue, postbox: PostboxImpl) { + assert(queue.isCurrent()) + + self.queue = queue self.postbox = postbox } public func keychainEntryForKey(_ key: String) -> Data? { + assert(self.queue.isCurrent()) + assert(!self.disposed) return self.postbox?.keychainTable.get(key) } @@ -1301,7 +1307,7 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration, } } -public final class Postbox { +final class PostboxImpl { public let queue: Queue public let seedConfiguration: SeedConfiguration private let basePath: String @@ -1368,8 +1374,6 @@ public final class Postbox { return value }() - public let mediaBox: MediaBox - private var nextUniqueId: UInt32 = 1 func takeNextUniqueId() -> UInt32 { assert(self.queue.isCurrent()) @@ -1454,10 +1458,7 @@ public final class Postbox { self.basePath = basePath self.seedConfiguration = seedConfiguration self.tempDir = tempDir - - postboxLog("MediaBox path: \(basePath + "/media")") - - self.mediaBox = MediaBox(basePath: self.basePath + "/media") + self.valueBox = valueBox self.metadataTable = MetadataTable(valueBox: self.valueBox, table: MetadataTable.tableSpec(0)) @@ -1677,26 +1678,9 @@ public final class Postbox { } public func keychainEntryForKey(_ key: String) -> Data? { - let metaDisposable = MetaDisposable() - self.keychainOperationsDisposable.add(metaDisposable) + precondition(self.queue.isCurrent()) - let semaphore = DispatchSemaphore(value: 0) - - var entry: Data? = nil - let disposable = (self.transaction({ transaction -> Data? in - return self.keychainTable.get(key) - }) |> afterDisposed { [weak self, weak metaDisposable] in - if let strongSelf = self, let metaDisposable = metaDisposable { - strongSelf.keychainOperationsDisposable.remove(metaDisposable) - } - }).start(next: { data in - entry = data - semaphore.signal() - }) - metaDisposable.set(disposable) - - semaphore.wait() - return entry + return self.keychainTable.get(key) } private var keychainOperationsDisposable = DisposableSet() @@ -2471,7 +2455,7 @@ public final class Postbox { private func internalTransaction(_ f: (Transaction) -> T) -> (result: T, updatedTransactionStateVersion: Int64?, updatedMasterClientId: Int64?) { self.valueBox.begin() self.afterBegin() - let transaction = Transaction(postbox: self) + let transaction = Transaction(queue: self.queue, postbox: self) let result = f(transaction) transaction.disposed = true let (updatedTransactionState, updatedMasterClientId) = self.beforeCommit() @@ -3653,3 +3637,585 @@ public final class Postbox { } } + +public class Postbox { + let queue: Queue + private let impl: QueueLocalObject + + public let seedConfiguration: SeedConfiguration + public let mediaBox: MediaBox + + init( + queue: Queue, + basePath: String, + seedConfiguration: SeedConfiguration, + valueBox: SqliteValueBox, + timestampForAbsoluteTimeBasedOperations: Int32, + isTemporary: Bool, + tempDir: TempBoxDirectory? + ) { + self.queue = queue + + self.seedConfiguration = seedConfiguration + + postboxLog("MediaBox path: \(basePath + "/media")") + self.mediaBox = MediaBox(basePath: basePath + "/media") + + self.impl = QueueLocalObject(queue: queue, generate: { + return PostboxImpl( + queue: queue, + basePath: basePath, + seedConfiguration: seedConfiguration, + valueBox: valueBox, + timestampForAbsoluteTimeBasedOperations: timestampForAbsoluteTimeBasedOperations, + isTemporary: isTemporary, + tempDir: tempDir + ) + }) + } + + public func keychainEntryForKey(_ key: String) -> Data? { + return self.impl.syncWith { impl -> Data? in + return impl.keychainEntryForKey(key) + } + } + + public func setKeychainEntryForKey(_ key: String, value: Data) { + self.impl.with { impl in + impl.setKeychainEntryForKey(key, value: value) + } + } + public func removeKeychainEntryForKey(_ key: String) { + self.impl.with { impl in + impl.removeKeychainEntryForKey(key) + } + } + + public func setCanBeginTransactions(_ value: Bool) { + self.impl.with { impl in + impl.setCanBeginTransactions(value) + } + } + + public func transactionSignal(userInteractive: Bool = false, _ f: @escaping(Subscriber, Transaction) -> Disposable) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.transactionSignal(userInteractive: userInteractive, f).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func transaction(userInteractive: Bool = false, ignoreDisabled: Bool = false, _ f: @escaping(Transaction) -> T) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.transaction(userInteractive: userInteractive, ignoreDisabled: ignoreDisabled, f).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func aroundMessageOfInterestHistoryViewForChatLocation( + _ chatLocation: ChatLocationInput, + count: Int, + clipHoles: Bool = true, + topTaggedMessageIdNamespaces: Set, + tagMask: MessageTags?, + appendMessagesFromTheSameGroup: Bool, + namespaces: MessageIdNamespaces, + orderStatistics: MessageHistoryViewOrderStatistics, + additionalData: [AdditionalMessageHistoryViewData] + ) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.aroundMessageOfInterestHistoryViewForChatLocation( + chatLocation, + count: count, + clipHoles: clipHoles, + topTaggedMessageIdNamespaces: topTaggedMessageIdNamespaces, + tagMask: tagMask, + appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, + namespaces: namespaces, + orderStatistics: orderStatistics, + additionalData: additionalData + ).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func aroundIdMessageHistoryViewForLocation( + _ chatLocation: ChatLocationInput, + count: Int, + clipHoles: Bool = true, + ignoreRelatedChats: Bool = false, + messageId: MessageId, + topTaggedMessageIdNamespaces: Set, + tagMask: MessageTags?, + appendMessagesFromTheSameGroup: Bool, + namespaces: MessageIdNamespaces, + orderStatistics: MessageHistoryViewOrderStatistics, + additionalData: [AdditionalMessageHistoryViewData] = [] + ) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.aroundIdMessageHistoryViewForLocation( + chatLocation, + count: count, + clipHoles: clipHoles, + ignoreRelatedChats: ignoreRelatedChats, + messageId: messageId, + topTaggedMessageIdNamespaces: topTaggedMessageIdNamespaces, + tagMask: tagMask, + appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, + namespaces: namespaces, + orderStatistics: orderStatistics, + additionalData: additionalData + ).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func aroundMessageHistoryViewForLocation( + _ chatLocation: ChatLocationInput, + anchor: HistoryViewInputAnchor, + count: Int, + clipHoles: Bool = true, + ignoreRelatedChats: Bool = false, + fixedCombinedReadStates: MessageHistoryViewReadState?, + topTaggedMessageIdNamespaces: Set, + tagMask: MessageTags?, + appendMessagesFromTheSameGroup: Bool, + namespaces: MessageIdNamespaces, + orderStatistics: MessageHistoryViewOrderStatistics, + additionalData: [AdditionalMessageHistoryViewData] = [] + ) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.aroundMessageHistoryViewForLocation( + chatLocation, + anchor: anchor, + count: count, + clipHoles: clipHoles, + ignoreRelatedChats: ignoreRelatedChats, + fixedCombinedReadStates: fixedCombinedReadStates, + topTaggedMessageIdNamespaces: topTaggedMessageIdNamespaces, + tagMask: tagMask, + appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, + namespaces: namespaces, + orderStatistics: orderStatistics, + additionalData: additionalData + ).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func messageIndexAtId(_ id: MessageId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.messageIndexAtId(id).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func messageAtId(_ id: MessageId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.messageAtId(id).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func messagesAtIds(_ ids: [MessageId]) -> Signal<[Message], NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.messagesAtIds(ids).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func tailChatListView( + groupId: PeerGroupId, + filterPredicate: ChatListFilterPredicate? = nil, + count: Int, + summaryComponents: ChatListEntrySummaryComponents + ) -> Signal<(ChatListView, ViewUpdateType), NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.tailChatListView( + groupId: groupId, + filterPredicate: filterPredicate, + count: count, + summaryComponents: summaryComponents + ).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func aroundChatListView( + groupId: PeerGroupId, + filterPredicate: ChatListFilterPredicate? = nil, + index: ChatListIndex, + count: Int, + summaryComponents: ChatListEntrySummaryComponents, + userInteractive: Bool = false + ) -> Signal<(ChatListView, ViewUpdateType), NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.aroundChatListView( + groupId: groupId, + filterPredicate: filterPredicate, + index: index, + count: count, + summaryComponents: summaryComponents, + userInteractive: userInteractive + ).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func contactPeerIdsView() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.contactPeerIdsView().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func contactPeersView(accountPeerId: PeerId?, includePresences: Bool) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.contactPeersView(accountPeerId: accountPeerId, includePresences: includePresences).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func searchContacts(query: String) -> Signal<([Peer], [PeerId: PeerPresence]), NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.searchContacts(query: query).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func searchPeers(query: String) -> Signal<[RenderedPeer], NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.searchPeers(query: query).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func peerView(id: PeerId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.peerView(id: id).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func multiplePeersView(_ ids: [PeerId]) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.multiplePeersView(ids).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func loadedPeerWithId(_ id: PeerId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.loadedPeerWithId(id).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func unreadMessageCountsView(items: [UnreadMessageCountsItem]) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.unreadMessageCountsView(items: items).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func recentPeers() -> Signal<[Peer], NoError> { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.recentPeers().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func stateView() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.stateView().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func messageHistoryHolesView() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.messageHistoryHolesView().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func chatListHolesView() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.chatListHolesView().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func unsentMessageIdsView() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.unsentMessageIdsView().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func synchronizePeerReadStatesView() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.synchronizePeerReadStatesView().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func itemCollectionsView( + orderedItemListCollectionIds: [Int32], + namespaces: [ItemCollectionId.Namespace], + aroundIndex: ItemCollectionViewEntryIndex?, + count: Int + ) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.itemCollectionsView( + orderedItemListCollectionIds: orderedItemListCollectionIds, + namespaces: namespaces, + aroundIndex: aroundIndex, + count: count + ).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func mergedOperationLogView(tag: PeerOperationLogTag, limit: Int) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.mergedOperationLogView(tag: tag, limit: limit).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func timestampBasedMessageAttributesView(tag: UInt16) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.timestampBasedMessageAttributesView(tag: tag).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func messageView(_ messageId: MessageId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.messageView(messageId).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func preferencesView(keys: [ValueBoxKey]) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.preferencesView(keys: keys).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func combinedView(keys: [PostboxViewKey]) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.combinedView(keys: keys).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func installStoreMessageAction(peerId: PeerId, _ f: @escaping ([StoreMessage], Transaction) -> Void) -> Disposable { + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.installStoreMessageAction(peerId: peerId, f)) + } + + return disposable + } + + public func isMasterClient() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.isMasterClient().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func becomeMasterClient() { + self.impl.with { impl in + impl.becomeMasterClient() + } + } + + public func clearCaches() { + self.impl.with { impl in + impl.clearCaches() + } + } + + public func optimizeStorage() -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.optimizeStorage().start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } + + public func failedMessageIdsView(peerId: PeerId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + + self.impl.with { impl in + disposable.set(impl.failedMessageIdsView(peerId: peerId).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)) + } + + return disposable + } + } +} diff --git a/submodules/Postbox/Sources/PostboxView.swift b/submodules/Postbox/Sources/PostboxView.swift index 4ee0772f8b..effaf9752c 100644 --- a/submodules/Postbox/Sources/PostboxView.swift +++ b/submodules/Postbox/Sources/PostboxView.swift @@ -4,7 +4,7 @@ public protocol PostboxView { } protocol MutablePostboxView { - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool func immutableView() -> PostboxView } @@ -15,7 +15,7 @@ final class CombinedMutableView { self.views = views } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for (_, view) in self.views { if view.replay(postbox: postbox, transaction: transaction) { diff --git a/submodules/Postbox/Sources/PreferencesView.swift b/submodules/Postbox/Sources/PreferencesView.swift index 4a7b809e03..10e5c7cd6e 100644 --- a/submodules/Postbox/Sources/PreferencesView.swift +++ b/submodules/Postbox/Sources/PreferencesView.swift @@ -4,7 +4,7 @@ final class MutablePreferencesView: MutablePostboxView { fileprivate let keys: Set fileprivate var values: [ValueBoxKey: PreferencesEntry] - init(postbox: Postbox, keys: Set) { + init(postbox: PostboxImpl, keys: Set) { self.keys = keys var values: [ValueBoxKey: PreferencesEntry] = [:] for key in keys { @@ -15,7 +15,7 @@ final class MutablePreferencesView: MutablePostboxView { self.values = values } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for operation in transaction.currentPreferencesOperations { switch operation { diff --git a/submodules/Postbox/Sources/SeedConfiguration.swift b/submodules/Postbox/Sources/SeedConfiguration.swift index c8913cc2a9..4d58d60961 100644 --- a/submodules/Postbox/Sources/SeedConfiguration.swift +++ b/submodules/Postbox/Sources/SeedConfiguration.swift @@ -45,7 +45,7 @@ func resolveChatListMessageTagSummaryResultCalculation(addSummary: MessageHistor return count > 0 } -func resolveChatListMessageTagSummaryResultCalculation(postbox: Postbox, peerId: PeerId, calculation: ChatListMessageTagSummaryResultCalculation?) -> Bool? { +func resolveChatListMessageTagSummaryResultCalculation(postbox: PostboxImpl, peerId: PeerId, calculation: ChatListMessageTagSummaryResultCalculation?) -> Bool? { guard let calculation = calculation else { return nil } diff --git a/submodules/Postbox/Sources/SynchronizeGroupMessageStatsView.swift b/submodules/Postbox/Sources/SynchronizeGroupMessageStatsView.swift index 3a169f9d36..a2865e2b50 100644 --- a/submodules/Postbox/Sources/SynchronizeGroupMessageStatsView.swift +++ b/submodules/Postbox/Sources/SynchronizeGroupMessageStatsView.swift @@ -3,11 +3,11 @@ import Foundation final class MutableSynchronizeGroupMessageStatsView: MutablePostboxView { fileprivate var groupsAndNamespaces: Set - init(postbox: Postbox) { + init(postbox: PostboxImpl) { self.groupsAndNamespaces = postbox.synchronizeGroupMessageStatsTable.get() } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if !transaction.currentUpdatedGroupSummarySynchronizeOperations.isEmpty { for (groupIdAndNamespace, value) in transaction.currentUpdatedGroupSummarySynchronizeOperations { diff --git a/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift b/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift index a253f1ba23..a64677b944 100644 --- a/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift +++ b/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift @@ -4,14 +4,14 @@ final class MutableTimestampBasedMessageAttributesView { let tag: UInt16 var head: TimestampBasedMessageAttributesEntry? - init(postbox: Postbox, tag: UInt16) { + init(postbox: PostboxImpl, tag: UInt16) { self.tag = tag self.head = postbox.timestampBasedMessageAttributesTable.head(tag: tag) postboxLog("MutableTimestampBasedMessageAttributesView: tag: \(tag) head: \(String(describing: self.head))") } - func replay(postbox: Postbox, operations: [TimestampBasedMessageAttributesOperation]) -> Bool { + func replay(postbox: PostboxImpl, operations: [TimestampBasedMessageAttributesOperation]) -> Bool { var updated = false var invalidatedHead = false for operation in operations { diff --git a/submodules/Postbox/Sources/TopChatMessageView.swift b/submodules/Postbox/Sources/TopChatMessageView.swift index be48793c97..9f276873f9 100644 --- a/submodules/Postbox/Sources/TopChatMessageView.swift +++ b/submodules/Postbox/Sources/TopChatMessageView.swift @@ -4,7 +4,7 @@ final class MutableTopChatMessageView: MutablePostboxView { private let peerIds: Set fileprivate var messages: [PeerId: Message] = [:] - init(postbox: Postbox, peerIds: Set) { + init(postbox: PostboxImpl, peerIds: Set) { self.peerIds = peerIds for peerId in self.peerIds { @@ -14,7 +14,7 @@ final class MutableTopChatMessageView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false for peerId in self.peerIds { if transaction.currentOperationsByPeerId[peerId] != nil { diff --git a/submodules/Postbox/Sources/UnreadMessageCountsView.swift b/submodules/Postbox/Sources/UnreadMessageCountsView.swift index f41a9a8150..8fe50bc914 100644 --- a/submodules/Postbox/Sources/UnreadMessageCountsView.swift +++ b/submodules/Postbox/Sources/UnreadMessageCountsView.swift @@ -21,7 +21,7 @@ public enum UnreadMessageCountsItemEntry { final class MutableUnreadMessageCountsView: MutablePostboxView { fileprivate var entries: [MutableUnreadMessageCountsItemEntry] - init(postbox: Postbox, items: [UnreadMessageCountsItem]) { + init(postbox: PostboxImpl, items: [UnreadMessageCountsItem]) { self.entries = items.map { item in switch item { case let .total(preferencesKey): @@ -34,7 +34,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView { } } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false var updatedPreferencesEntry: PreferencesEntry? @@ -133,12 +133,12 @@ final class MutableCombinedReadStateView: MutablePostboxView { private let peerId: PeerId fileprivate var state: CombinedPeerReadState? - init(postbox: Postbox, peerId: PeerId) { + init(postbox: PostboxImpl, peerId: PeerId) { self.peerId = peerId self.state = postbox.readStateTable.getCombinedState(peerId) } - func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { + func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool { var updated = false if transaction.alteredInitialPeerCombinedReadStates[self.peerId] != nil { diff --git a/submodules/Postbox/Sources/ViewTracker.swift b/submodules/Postbox/Sources/ViewTracker.swift index c76ff7dd21..0660060455 100644 --- a/submodules/Postbox/Sources/ViewTracker.swift +++ b/submodules/Postbox/Sources/ViewTracker.swift @@ -222,7 +222,7 @@ final class ViewTracker { self.combinedViews.remove(index) } - func refreshViewsDueToExternalTransaction(postbox: Postbox, fetchUnsentMessageIds: () -> [MessageId], fetchSynchronizePeerReadStateOperations: () -> [PeerId: PeerReadStateSynchronizationOperation]) { + func refreshViewsDueToExternalTransaction(postbox: PostboxImpl, fetchUnsentMessageIds: () -> [MessageId], fetchSynchronizePeerReadStateOperations: () -> [PeerId: PeerReadStateSynchronizationOperation]) { var updateTrackedHoles = false for (mutableView, pipe) in self.messageHistoryViews.copyItems() { @@ -259,7 +259,7 @@ final class ViewTracker { } } - func updateViews(postbox: Postbox, transaction: PostboxTransaction) { + func updateViews(postbox: PostboxImpl, transaction: PostboxTransaction) { var updateTrackedHoles = false if let currentUpdatedState = transaction.currentUpdatedState { diff --git a/submodules/Postbox/Sources/Views.swift b/submodules/Postbox/Sources/Views.swift index 255489a3fe..133d6cebb8 100644 --- a/submodules/Postbox/Sources/Views.swift +++ b/submodules/Postbox/Sources/Views.swift @@ -283,7 +283,7 @@ public enum PostboxViewKey: Hashable { } } -func postboxViewForKey(postbox: Postbox, key: PostboxViewKey) -> MutablePostboxView { +func postboxViewForKey(postbox: PostboxImpl, key: PostboxViewKey) -> MutablePostboxView { switch key { case let .itemCollectionInfos(namespaces): return MutableItemCollectionInfosView(postbox: postbox, namespaces: namespaces) diff --git a/submodules/SSignalKit/SwiftSignalKit/Source/QueueLocalObject.swift b/submodules/SSignalKit/SwiftSignalKit/Source/QueueLocalObject.swift index 9bdca6434f..9265f752ba 100644 --- a/submodules/SSignalKit/SwiftSignalKit/Source/QueueLocalObject.swift +++ b/submodules/SSignalKit/SwiftSignalKit/Source/QueueLocalObject.swift @@ -29,7 +29,7 @@ public final class QueueLocalObject { } } - public func syncWith(_ f: @escaping (T) -> R) -> R? { + public func syncWith(_ f: @escaping (T) -> R) -> R { var result: R? self.queue.sync { if let valueRef = self.valueRef { @@ -37,7 +37,7 @@ public final class QueueLocalObject { result = f(value) } } - return result + return result! } public func signalWith(_ f: @escaping (T, Subscriber) -> Disposable) -> Signal { diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift index b6b70ca702..39fe42d1b7 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift @@ -287,13 +287,10 @@ public final class PeerChannelMemberCategoriesContextsManager { private func getContext(engine: TelegramEngine, postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId, key: PeerChannelMemberContextKey, requestUpdate: Bool, updated: @escaping (ChannelMemberListState) -> Void) -> (Disposable, PeerChannelMemberCategoryControl?) { assert(Queue.mainQueue().isCurrent()) - if let (disposable, control) = self.impl.syncWith({ impl in + let (disposable, control) = self.impl.syncWith({ impl in return impl.getContext(engine: engine, postbox: postbox, network: network, accountPeerId: accountPeerId, peerId: peerId, key: key, requestUpdate: requestUpdate, updated: updated) - }) { - return (disposable, control) - } else { - return (EmptyDisposable, nil) - } + }) + return (disposable, control) } public func externallyAdded(peerId: PeerId, participant: RenderedChannelParticipant) { @@ -494,7 +491,7 @@ public final class PeerChannelMemberCategoriesContextsManager { subscriber.putNext(value) }) }) - return disposable ?? EmptyDisposable + return disposable } |> runOn(Queue.mainQueue()) } @@ -557,7 +554,7 @@ public final class PeerChannelMemberCategoriesContextsManager { let disposable = strongSelf.impl.syncWith({ impl -> Disposable in return impl.profileData(postbox: postbox, network: network, peerId: peerId, customData: customData) }) - return disposable ?? EmptyDisposable + return disposable } |> runOn(Queue.mainQueue()) } @@ -574,7 +571,7 @@ public final class PeerChannelMemberCategoriesContextsManager { subscriber.putNext(value) }) }) - return disposable ?? EmptyDisposable + return disposable } |> runOn(Queue.mainQueue()) }