no message

This commit is contained in:
Peter
2017-03-18 17:57:52 +03:00
parent 370f76636a
commit c2192b598c
5 changed files with 144 additions and 0 deletions

View File

@@ -157,6 +157,8 @@
D0BC386C1E3FCEE50044D6FE /* MultiplePeersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BC386B1E3FCEE50044D6FE /* MultiplePeersView.swift */; };
D0BC38721E409E670044D6FE /* RenderedPeer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BC38711E409E670044D6FE /* RenderedPeer.swift */; };
D0BC38731E409E670044D6FE /* RenderedPeer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BC38711E409E670044D6FE /* RenderedPeer.swift */; };
D0BE38391E7C1FD4000079AF /* ItemCollectionInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BE38381E7C1FD4000079AF /* ItemCollectionInfoView.swift */; };
D0BE383A1E7C1FD4000079AF /* ItemCollectionInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BE38381E7C1FD4000079AF /* ItemCollectionInfoView.swift */; };
D0BEAF631E54B2FA00BD963D /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BEAF621E54B2FA00BD963D /* AccountManager.swift */; };
D0BEAF641E54B2FA00BD963D /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BEAF621E54B2FA00BD963D /* AccountManager.swift */; };
D0BEAF671E54B33900BD963D /* AccountRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BEAF661E54B33900BD963D /* AccountRecord.swift */; };
@@ -353,6 +355,7 @@
D0B844501DAC04FE005F29E1 /* PeerPresence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeerPresence.swift; sourceTree = "<group>"; };
D0BC386B1E3FCEE50044D6FE /* MultiplePeersView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultiplePeersView.swift; sourceTree = "<group>"; };
D0BC38711E409E670044D6FE /* RenderedPeer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RenderedPeer.swift; sourceTree = "<group>"; };
D0BE38381E7C1FD4000079AF /* ItemCollectionInfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemCollectionInfoView.swift; sourceTree = "<group>"; };
D0BEAF621E54B2FA00BD963D /* AccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountManager.swift; sourceTree = "<group>"; };
D0BEAF661E54B33900BD963D /* AccountRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountRecord.swift; sourceTree = "<group>"; };
D0BEAF691E54B5FB00BD963D /* AccountManagerMetadataTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountManagerMetadataTable.swift; sourceTree = "<group>"; };
@@ -632,6 +635,7 @@
D0DF0C8E1D81A350008AEB01 /* PeerView.swift */,
D021E0DB1DB5237C00C6B04F /* ItemCollectionsView.swift */,
D0FA0AC61E77F0A2005BB9B7 /* ItemCollectionInfosView.swift */,
D0BE38381E7C1FD4000079AF /* ItemCollectionInfoView.swift */,
D0A18D661E16874D004C6734 /* UnreadMessageCountsView.swift */,
D0F019FC1E1DA0CC00F05AB3 /* PeerMergedOperationLogView.swift */,
D0AAD1B41E32673C00D5B9DE /* TimestampBasedMessageAttributesView.swift */,
@@ -949,6 +953,7 @@
D073CE7F1DCBF3B4007511FD /* ItemCollection.swift in Sources */,
D0F7B1D91E045C6A007EB8A5 /* OrderStatisticTable.swift in Sources */,
D073CEA01DCBF3C1007511FD /* ItemCollectionsView.swift in Sources */,
D0BE383A1E7C1FD4000079AF /* ItemCollectionInfoView.swift in Sources */,
D0B418491D7DFE20004562A4 /* ChatListView.swift in Sources */,
D0F7B1D61E045C6A007EB8A5 /* ContactTable.swift in Sources */,
D0F7B1D11E045C6A007EB8A5 /* PeerTable.swift in Sources */,
@@ -1069,6 +1074,7 @@
D0AD23271E194D1C00A7089A /* PeerOperationLogTable.swift in Sources */,
D021E0D41DB4FAE100C6B04F /* ItemCollection.swift in Sources */,
D0D510F91D63BCC200A97B8A /* IntermediateMessage.swift in Sources */,
D0BE38391E7C1FD4000079AF /* ItemCollectionInfoView.swift in Sources */,
D0F9E86B1C59719800037222 /* ChatListView.swift in Sources */,
D0D949F51D35353900740E02 /* MappedFile.swift in Sources */,
D003E4E61B38DBDB00C22CBC /* MessageHistoryView.swift in Sources */,

View File

@@ -49,6 +49,23 @@ final class ItemCollectionInfoTable: Table {
}
}
func getInfo(id: ItemCollectionId) -> ItemCollectionInfo? {
var infoKey: ValueBoxKey?
self.valueBox.range(self.table, start: self.lowerBound(namespace: id.namespace), end: self.upperBound(namespace: id.namespace), keys: { key in
let keyId = ItemCollectionId(namespace: id.namespace, id: key.getInt64(4 + 4))
if keyId == id {
infoKey = key
return false
}
return true
}, limit: 0)
if let infoKey = infoKey, let value = self.valueBox.get(self.table, key: infoKey), let info = Decoder(buffer: value).decodeRootObject() as? ItemCollectionInfo {
return info
} else {
return nil
}
}
func lowerCollectionId(namespaceList: [ItemCollectionId.Namespace], collectionId: ItemCollectionId, index: Int32) -> (ItemCollectionId, Int32)? {
var currentNamespace = collectionId.namespace
var currentKey = self.key(collectionId: collectionId, index: index)

View File

@@ -0,0 +1,65 @@
import Foundation
final class MutableItemCollectionInfoView: MutablePostboxView {
let id: ItemCollectionId
var info: ItemCollectionInfo?
init(postbox: Postbox, id: ItemCollectionId) {
self.id = id
let infos = postbox.itemCollectionInfoTable.getInfos(namespace: id.namespace)
for (_, infoId, info) in infos {
if id == infoId {
self.info = info
break
}
}
}
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
if transaction.currentItemCollectionInfosOperations.isEmpty {
return false
}
var updated = false
var reloadInfosNamespaces = Set<ItemCollectionId.Namespace>()
for operation in transaction.currentItemCollectionInfosOperations {
switch operation {
case let .replaceInfos(namespace):
reloadInfosNamespaces.insert(namespace)
}
}
if !reloadInfosNamespaces.isEmpty && reloadInfosNamespaces.contains(self.id.namespace) {
updated = true
let infos = postbox.itemCollectionInfoTable.getInfos(namespace: id.namespace)
var found = false
for (_, infoId, info) in infos {
if id == infoId {
self.info = info
found = true
break
}
}
if !found {
self.info = nil
}
}
return updated
}
func immutableView() -> PostboxView {
return ItemCollectionInfoView(self)
}
}
public final class ItemCollectionInfoView: PostboxView {
public let id: ItemCollectionId
public let info: ItemCollectionInfo?
init(_ view: MutableItemCollectionInfoView) {
self.id = view.id
self.info = view.info
}
}

View File

@@ -211,6 +211,30 @@ public final class Modifier {
self.postbox?.replaceItemCollections(namespace: namespace, itemCollections: itemCollections)
}
public func replaceItemCollectionInfos(namespace: ItemCollectionId.Namespace, itemCollectionInfos: [(ItemCollectionId, ItemCollectionInfo)]) {
self.postbox?.replaceItemCollectionInfos(namespace: namespace, itemCollectionInfos: itemCollectionInfos)
}
public func replaceItemCollectionItems(collectionId: ItemCollectionId, items: [ItemCollectionItem]) {
self.postbox?.replaceItemCollectionItems(collectionId: collectionId, items: items)
}
public func removeItemCollection(collectionId: ItemCollectionId) {
self.postbox?.removeItemCollection(collectionId: collectionId)
}
public func getItemCollectionsInfos(namespace: ItemCollectionId.Namespace) -> [(ItemCollectionId, ItemCollectionInfo)] {
if let postbox = self.postbox {
return postbox.itemCollectionInfoTable.getInfos(namespace: namespace).map { ($0.1, $0.2) }
} else {
return []
}
}
public func getItemCollectionInfo(collectionId: ItemCollectionId) -> ItemCollectionInfo? {
return self.postbox?.itemCollectionInfoTable.getInfo(id: collectionId)
}
public func getItemCollectionItems(collectionId: ItemCollectionId) -> [ItemCollectionItem] {
if let postbox = self.postbox {
return postbox.itemCollectionItemTable.collectionItems(collectionId: collectionId)
@@ -1259,6 +1283,27 @@ public final class Postbox {
self.currentItemCollectionInfosOperations.append(.replaceInfos(namespace))
}
fileprivate func replaceItemCollectionInfos(namespace: ItemCollectionId.Namespace, itemCollectionInfos: [(ItemCollectionId, ItemCollectionInfo)]) {
self.itemCollectionInfoTable.replaceInfos(namespace: namespace, infos: itemCollectionInfos)
self.currentItemCollectionInfosOperations.append(.replaceInfos(namespace))
}
fileprivate func replaceItemCollectionItems(collectionId: ItemCollectionId, items: [ItemCollectionItem]) {
self.itemCollectionItemTable.replaceItems(collectionId: collectionId, items: items)
if self.currentItemCollectionItemsOperations[collectionId] == nil {
self.currentItemCollectionItemsOperations[collectionId] = []
}
self.currentItemCollectionItemsOperations[collectionId]!.append(.replaceItems)
}
fileprivate func removeItemCollection(collectionId: ItemCollectionId) {
var infos = self.itemCollectionInfoTable.getInfos(namespace: collectionId.namespace)
if let index = infos.index(where: { $0.1 == collectionId }) {
infos.remove(at: index)
self.replaceItemCollectionInfos(namespace: collectionId.namespace, itemCollectionInfos: infos.map { ($0.1, $0.2) })
}
}
fileprivate func filterStoredMessageIds(_ messageIds: Set<MessageId>) -> Set<MessageId> {
var filteredIds = Set<MessageId>()

View File

@@ -2,6 +2,7 @@ import Foundation
public enum PostboxViewKey: Hashable {
case itemCollectionInfos(namespaces: [ItemCollectionId.Namespace])
case itemCollectionInfo(id: ItemCollectionId)
case peerChatState(peerId: PeerId)
public var hashValue: Int {
@@ -10,6 +11,8 @@ public enum PostboxViewKey: Hashable {
return 0
case let .peerChatState(peerId):
return peerId.hashValue
case let .itemCollectionInfo(id):
return id.hashValue
}
}
@@ -21,6 +24,12 @@ public enum PostboxViewKey: Hashable {
} else {
return false
}
case let .itemCollectionInfo(id):
if case .itemCollectionInfo(id) = rhs {
return true
} else {
return false
}
case let .peerChatState(peerId):
if case .peerChatState(peerId) = rhs {
return true
@@ -35,6 +44,8 @@ func postboxViewForKey(postbox: Postbox, key: PostboxViewKey) -> MutablePostboxV
switch key {
case let .itemCollectionInfos(namespaces):
return MutableItemCollectionInfosView(postbox: postbox, namespaces: namespaces)
case let .itemCollectionInfo(id):
return MutableItemCollectionInfoView(postbox: postbox, id: id)
case let .peerChatState(peerId):
return MutablePeerChatStateView(postbox: postbox, peerId: peerId)
}