From f751e22384cf4db4a65d76e6eb200e3f47629960 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 3 Aug 2018 23:21:57 +0300 Subject: [PATCH] no message --- Postbox/MediaBox.swift | 7 +++++ Postbox/MessageHistoryView.swift | 2 +- Postbox/PeerNotificationSettingsView.swift | 33 ++++++++++++++-------- Postbox/PeerView.swift | 18 +++++++++++- Postbox/Postbox.swift | 2 +- Postbox/UnreadMessageCountsView.swift | 4 +-- Postbox/Views.swift | 26 ++++++++--------- 7 files changed, 63 insertions(+), 29 deletions(-) diff --git a/Postbox/MediaBox.swift b/Postbox/MediaBox.swift index c452c6e85c..49e5783635 100644 --- a/Postbox/MediaBox.swift +++ b/Postbox/MediaBox.swift @@ -579,6 +579,13 @@ public final class MediaBox { } } + public func storeCachedResourceRepresentation(_ resource: MediaResource, representation: CachedMediaResourceRepresentation, data: Data) { + self.dataQueue.async { + let path = self.cachedRepresentationPathForId(resource.id, representation: representation) + let _ = try? data.write(to: URL(fileURLWithPath: path)) + } + } + public func cachedResourceRepresentation(_ resource: MediaResource, representation: CachedMediaResourceRepresentation, complete: Bool) -> Signal { return Signal { subscriber in let disposable = MetaDisposable() diff --git a/Postbox/MessageHistoryView.swift b/Postbox/MessageHistoryView.swift index 0f7d05d94c..58147dbf75 100644 --- a/Postbox/MessageHistoryView.swift +++ b/Postbox/MessageHistoryView.swift @@ -1614,7 +1614,7 @@ public final class MessageHistoryView { if !entries.isEmpty && mutableView.clipHoles { var referenceIndex = entries.count - 1 for i in 0 ..< entries.count { - if self.anchorIndex.isLess(than: entries[i].index) { + if self.anchorIndex.isLessOrEqual(to: entries[i].index) { referenceIndex = i break } diff --git a/Postbox/PeerNotificationSettingsView.swift b/Postbox/PeerNotificationSettingsView.swift index 1fbfa9e09c..0cf5aaf5b2 100644 --- a/Postbox/PeerNotificationSettingsView.swift +++ b/Postbox/PeerNotificationSettingsView.swift @@ -1,18 +1,29 @@ import Foundation final class MutablePeerNotificationSettingsView: MutablePostboxView { - let peerId: PeerId - var notificationSettings: PeerNotificationSettings? + let peerIds: Set + var notificationSettings: [PeerId: PeerNotificationSettings] - init(postbox: Postbox, peerId: PeerId) { - self.peerId = peerId - self.notificationSettings = postbox.peerNotificationSettingsTable.getEffective(peerId) + init(postbox: Postbox, peerIds: Set) { + self.peerIds = peerIds + self.notificationSettings = [:] + for peerId in peerIds { + if let settings = postbox.peerNotificationSettingsTable.getEffective(peerId) { + self.notificationSettings[peerId] = settings + } + } } func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool { - if let notificationSettings = transaction.currentUpdatedPeerNotificationSettings[self.peerId] { - self.notificationSettings = notificationSettings - return true + if !transaction.currentUpdatedPeerNotificationSettings.isEmpty { + var updated = false + for peerId in self.peerIds { + if let settings = transaction.currentUpdatedPeerNotificationSettings[peerId] { + self.notificationSettings[peerId] = settings + updated = true + } + } + return updated } else { return false } @@ -24,11 +35,11 @@ final class MutablePeerNotificationSettingsView: MutablePostboxView { } public final class PeerNotificationSettingsView: PostboxView { - public let peerId: PeerId - public let notificationSettings: PeerNotificationSettings? + public let peerIds: Set + public let notificationSettings: [PeerId: PeerNotificationSettings] init(_ view: MutablePeerNotificationSettingsView) { - self.peerId = view.peerId + self.peerIds = view.peerIds self.notificationSettings = view.notificationSettings } } diff --git a/Postbox/PeerView.swift b/Postbox/PeerView.swift index 01187b104e..6c4a6b8d09 100644 --- a/Postbox/PeerView.swift +++ b/Postbox/PeerView.swift @@ -1,7 +1,22 @@ import Foundation +public struct PeerViewComponents: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let cachedData = PeerViewComponents(rawValue: 1 << 0) + public static let subPeers = PeerViewComponents(rawValue: 1 << 1) + public static let messages = PeerViewComponents(rawValue: 1 << 2) + + public static let all: PeerViewComponents = [.cachedData, .subPeers, .messages] +} + final class MutablePeerView: MutablePostboxView { let peerId: PeerId + let components: PeerViewComponents var notificationSettings: PeerNotificationSettings? var cachedData: CachedPeerData? var peers: [PeerId: Peer] = [:] @@ -9,7 +24,8 @@ final class MutablePeerView: MutablePostboxView { var messages: [MessageId: Message] = [:] var peerIsContact: Bool - init(postbox: Postbox, peerId: PeerId) { + init(postbox: Postbox, peerId: PeerId, components: PeerViewComponents) { + self.components = components let cachedData = postbox.cachedPeerDataTable.get(peerId) let peerIsContact = postbox.contactsTable.isContact(peerId: peerId) diff --git a/Postbox/Postbox.swift b/Postbox/Postbox.swift index 5ac87b4820..d5c6e7fa98 100644 --- a/Postbox/Postbox.swift +++ b/Postbox/Postbox.swift @@ -2773,7 +2773,7 @@ public final class Postbox { public func peerView(id: PeerId) -> Signal { return self.transactionSignal { subscriber, transaction in - let view = MutablePeerView(postbox: self, peerId: id) + let view = MutablePeerView(postbox: self, peerId: id, components: .all) let (index, signal) = self.viewTracker.addPeerView(view) subscriber.putNext(PeerView(view)) diff --git a/Postbox/UnreadMessageCountsView.swift b/Postbox/UnreadMessageCountsView.swift index 6c7ddd4ffc..fcc8117547 100644 --- a/Postbox/UnreadMessageCountsView.swift +++ b/Postbox/UnreadMessageCountsView.swift @@ -22,7 +22,7 @@ private enum MutableUnreadMessageCountsItemEntry { case group(PeerGroupId, ChatListGroupReferenceUnreadCounters) } -enum UnreadMessageCountsItemEntry { +public enum UnreadMessageCountsItemEntry { case total(ChatListTotalUnreadState) case peer(PeerId, Int32) case group(PeerGroupId, Int32) @@ -88,7 +88,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView { } public final class UnreadMessageCountsView: PostboxView { - private let entries: [UnreadMessageCountsItemEntry] + public let entries: [UnreadMessageCountsItemEntry] init(_ view: MutableUnreadMessageCountsView) { self.entries = view.entries.map { entry in diff --git a/Postbox/Views.swift b/Postbox/Views.swift index 862d96ed60..88a35629fe 100644 --- a/Postbox/Views.swift +++ b/Postbox/Views.swift @@ -10,14 +10,14 @@ public enum PostboxViewKey: Hashable { case accessChallengeData case preferences(keys: Set) case globalMessageTags(globalTag: GlobalMessageTags, position: MessageIndex, count: Int, groupingPredicate: ((Message, Message) -> Bool)?) - case peer(peerId: PeerId) + case peer(peerId: PeerId, components: PeerViewComponents) case pendingMessageActions(type: PendingMessageActionType) case invalidatedMessageHistoryTagSummaries(tagMask: MessageTags, namespace: MessageId.Namespace) case pendingMessageActionsSummary(type: PendingMessageActionType, peerId: PeerId, namespace: MessageId.Namespace) case historyTagSummaryView(tag: MessageTags, peerId: PeerId, namespace: MessageId.Namespace) case cachedPeerData(peerId: PeerId) case unreadCounts(items: [UnreadMessageCountsItem]) - case peerNotificationSettings(peerId: PeerId) + case peerNotificationSettings(peerIds: Set) case pendingPeerNotificationSettings case messageOfInterestHole(location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int) case chatListTopPeers(groupId: PeerGroupId) @@ -48,7 +48,7 @@ public enum PostboxViewKey: Hashable { return 3 case .globalMessageTags: return 4 - case let .peer(peerId): + case let .peer(peerId, _): return peerId.hashValue case let .pendingMessageActions(type): return type.hashValue @@ -62,8 +62,8 @@ public enum PostboxViewKey: Hashable { return peerId.hashValue case .unreadCounts: return 5 - case let .peerNotificationSettings(peerId): - return 6 &+ 31 &* peerId.hashValue + case let .peerNotificationSettings(peerIds): + return 6 case .pendingPeerNotificationSettings: return 7 case let .messageOfInterestHole(location, namespace, count): @@ -141,8 +141,8 @@ public enum PostboxViewKey: Hashable { } else { return false } - case let .peer(peerId): - if case .peer(peerId) = rhs { + case let .peer(peerId, components): + if case .peer(peerId, components) = rhs { return true } else { return false @@ -183,8 +183,8 @@ public enum PostboxViewKey: Hashable { } else { return false } - case let .peerNotificationSettings(peerId): - if case .peerNotificationSettings(peerId) = rhs { + case let .peerNotificationSettings(peerIds): + if case .peerNotificationSettings(peerIds) = rhs { return true } else { return false @@ -267,8 +267,8 @@ func postboxViewForKey(postbox: Postbox, key: PostboxViewKey) -> MutablePostboxV return MutablePreferencesView(postbox: postbox, keys: keys) case let .globalMessageTags(globalTag, position, count, groupingPredicate): return MutableGlobalMessageTagsView(postbox: postbox, globalTag: globalTag, position: position, count: count, groupingPredicate: groupingPredicate) - case let .peer(peerId): - return MutablePeerView(postbox: postbox, peerId: peerId) + case let .peer(peerId, components): + return MutablePeerView(postbox: postbox, peerId: peerId, components: components) case let .pendingMessageActions(type): return MutablePendingMessageActionsView(postbox: postbox, type: type) case let .invalidatedMessageHistoryTagSummaries(tagMask, namespace): @@ -281,8 +281,8 @@ func postboxViewForKey(postbox: Postbox, key: PostboxViewKey) -> MutablePostboxV return MutableCachedPeerDataView(postbox: postbox, peerId: peerId) case let .unreadCounts(items): return MutableUnreadMessageCountsView(postbox: postbox, items: items) - case let .peerNotificationSettings(peerId): - return MutablePeerNotificationSettingsView(postbox: postbox, peerId: peerId) + case let .peerNotificationSettings(peerIds): + return MutablePeerNotificationSettingsView(postbox: postbox, peerIds: peerIds) case .pendingPeerNotificationSettings: return MutablePendingPeerNotificationSettingsView(postbox: postbox) case let .messageOfInterestHole(location, namespace, count):