mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Isolate postbox
This commit is contained in:
parent
c808238571
commit
d35acc8283
@ -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 {
|
||||
|
@ -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<Bool, NoError>.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, [])
|
||||
}
|
||||
|
@ -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<ListViewItemNode>()
|
||||
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 {
|
||||
|
@ -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
|
||||
|
@ -20,7 +20,9 @@ public func preloadVideoResource(postbox: Postbox, resourceReference: MediaResou
|
||||
|> deliverOn(queue)
|
||||
|> mapToSignal { result -> Signal<Never, MediaFrameSourceSeekError> 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)
|
||||
|
@ -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
|
||||
|
@ -5,13 +5,13 @@ final class MutableAllChatListHolesView: MutablePostboxView {
|
||||
private var holes = Set<ChatListHole>()
|
||||
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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<PeerId>, removed: Set<PeerId>), 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<PeerId>, removed: Set<PeerId>), 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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)] = []
|
||||
|
@ -15,7 +15,7 @@ final class MutableContactPeersView {
|
||||
self.includePresences = includePresences
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, replacePeerIds: Set<PeerId>?, updatedPeerPresences: [PeerId: PeerPresence]) -> Bool {
|
||||
func replay(postbox: PostboxImpl, replacePeerIds: Set<PeerId>?, updatedPeerPresences: [PeerId: PeerPresence]) -> Bool {
|
||||
var updated = false
|
||||
if let replacePeerIds = replacePeerIds {
|
||||
let removedPeerIds = self.peerIds.subtracting(replacePeerIds)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -5,7 +5,7 @@ final class MutableInvalidatedMessageHistoryTagSummariesView: MutablePostboxView
|
||||
|
||||
var entries = Set<InvalidatedMessageHistoryTagsSummaryEntry>()
|
||||
|
||||
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 {
|
||||
|
@ -4,7 +4,7 @@ final class MutableItemCollectionIdsView: MutablePostboxView {
|
||||
let namespaces: [ItemCollectionId.Namespace]
|
||||
var idsByNamespace: [ItemCollectionId.Namespace: Set<ItemCollectionId>]
|
||||
|
||||
init(postbox: Postbox, namespaces: [ItemCollectionId.Namespace]) {
|
||||
init(postbox: PostboxImpl, namespaces: [ItemCollectionId.Namespace]) {
|
||||
self.namespaces = namespaces
|
||||
|
||||
var idsByNamespace: [ItemCollectionId.Namespace: Set<ItemCollectionId>] = [:]
|
||||
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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)] {
|
||||
|
@ -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<PeerId>()
|
||||
|
||||
@ -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))
|
||||
|
@ -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<PeerIdAndNamespace>()
|
||||
|
||||
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))
|
||||
|
@ -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):
|
||||
|
@ -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 {
|
||||
|
@ -5,7 +5,7 @@ final class MutableMessagesView: MutablePostboxView {
|
||||
private let peerIds: Set<PeerId>
|
||||
fileprivate var messages: [MessageId: Message] = [:]
|
||||
|
||||
init(postbox: Postbox, ids: Set<MessageId>) {
|
||||
init(postbox: PostboxImpl, ids: Set<MessageId>) {
|
||||
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<MessageId>()
|
||||
for peerId in self.peerIds {
|
||||
if let operations = transaction.currentOperationsByPeerId[peerId] {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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] {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -195,7 +195,7 @@ final class PeerNotificationSettingsTable: Table {
|
||||
self.updatedInitialSettings.removeAll()
|
||||
}
|
||||
|
||||
func transactionParticipationInTotalUnreadCountUpdates(postbox: Postbox) -> (added: Set<PeerId>, removed: Set<PeerId>) {
|
||||
func transactionParticipationInTotalUnreadCountUpdates(postbox: PostboxImpl) -> (added: Set<PeerId>, removed: Set<PeerId>) {
|
||||
var added = Set<PeerId>()
|
||||
var removed = Set<PeerId>()
|
||||
|
||||
|
@ -4,7 +4,7 @@ final class MutablePeerNotificationSettingsView: MutablePostboxView {
|
||||
let peerIds: Set<PeerId>
|
||||
var notificationSettings: [PeerId: PeerNotificationSettings]
|
||||
|
||||
init(postbox: Postbox, peerIds: Set<PeerId>) {
|
||||
init(postbox: PostboxImpl, peerIds: Set<PeerId>) {
|
||||
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 {
|
||||
|
@ -4,7 +4,7 @@ final class MutablePeerPresencesView: MutablePostboxView {
|
||||
fileprivate let ids: Set<PeerId>
|
||||
fileprivate var presences: [PeerId: PeerPresence] = [:]
|
||||
|
||||
init(postbox: Postbox, ids: Set<PeerId>) {
|
||||
init(postbox: PostboxImpl, ids: Set<PeerId>) {
|
||||
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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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<T>(_ 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<PostboxImpl>
|
||||
|
||||
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<T, E>(userInteractive: Bool = false, _ f: @escaping(Subscriber<T, E>, Transaction) -> Disposable) -> Signal<T, E> {
|
||||
return Signal<T, E> { 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<T>(userInteractive: Bool = false, ignoreDisabled: Bool = false, _ f: @escaping(Transaction) -> T) -> Signal<T, NoError> {
|
||||
return Signal<T, NoError> { 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<MessageId.Namespace>,
|
||||
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<MessageId.Namespace>,
|
||||
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<MessageId.Namespace>,
|
||||
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<MessageIndex?, NoError> {
|
||||
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<Message?, NoError> {
|
||||
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<ContactPeerIdsView, NoError> {
|
||||
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<ContactPeersView, NoError> {
|
||||
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<PeerView, NoError> {
|
||||
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<MultiplePeersView, NoError> {
|
||||
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<Peer, NoError> {
|
||||
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<UnreadMessageCountsView, NoError> {
|
||||
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<PostboxStateView, NoError> {
|
||||
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<MessageHistoryHolesView, NoError> {
|
||||
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<ChatListHolesView, NoError> {
|
||||
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<UnsentMessageIdsView, NoError> {
|
||||
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<SynchronizePeerReadStatesView, NoError> {
|
||||
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<ItemCollectionsView, NoError> {
|
||||
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<PeerMergedOperationLogView, NoError> {
|
||||
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<TimestampBasedMessageAttributesView, NoError> {
|
||||
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<MessageView, NoError> {
|
||||
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<PreferencesView, NoError> {
|
||||
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<CombinedView, NoError> {
|
||||
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<Bool, NoError> {
|
||||
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<Never, NoError> {
|
||||
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<FailedMessageIdsView, NoError> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -4,7 +4,7 @@ final class MutablePreferencesView: MutablePostboxView {
|
||||
fileprivate let keys: Set<ValueBoxKey>
|
||||
fileprivate var values: [ValueBoxKey: PreferencesEntry]
|
||||
|
||||
init(postbox: Postbox, keys: Set<ValueBoxKey>) {
|
||||
init(postbox: PostboxImpl, keys: Set<ValueBoxKey>) {
|
||||
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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ import Foundation
|
||||
final class MutableSynchronizeGroupMessageStatsView: MutablePostboxView {
|
||||
fileprivate var groupsAndNamespaces: Set<PeerGroupAndNamespace>
|
||||
|
||||
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 {
|
||||
|
@ -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 {
|
||||
|
@ -4,7 +4,7 @@ final class MutableTopChatMessageView: MutablePostboxView {
|
||||
private let peerIds: Set<PeerId>
|
||||
fileprivate var messages: [PeerId: Message] = [:]
|
||||
|
||||
init(postbox: Postbox, peerIds: Set<PeerId>) {
|
||||
init(postbox: PostboxImpl, peerIds: Set<PeerId>) {
|
||||
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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -29,7 +29,7 @@ public final class QueueLocalObject<T: AnyObject> {
|
||||
}
|
||||
}
|
||||
|
||||
public func syncWith<R>(_ f: @escaping (T) -> R) -> R? {
|
||||
public func syncWith<R>(_ f: @escaping (T) -> R) -> R {
|
||||
var result: R?
|
||||
self.queue.sync {
|
||||
if let valueRef = self.valueRef {
|
||||
@ -37,7 +37,7 @@ public final class QueueLocalObject<T: AnyObject> {
|
||||
result = f(value)
|
||||
}
|
||||
}
|
||||
return result
|
||||
return result!
|
||||
}
|
||||
|
||||
public func signalWith<R, E>(_ f: @escaping (T, Subscriber<R, E>) -> Disposable) -> Signal<R, E> {
|
||||
|
@ -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())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user