mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
55
submodules/Postbox/Sources/ItemCollectionIdsView.swift
Normal file
55
submodules/Postbox/Sources/ItemCollectionIdsView.swift
Normal file
@@ -0,0 +1,55 @@
|
||||
import Foundation
|
||||
|
||||
final class MutableItemCollectionIdsView: MutablePostboxView {
|
||||
let namespaces: [ItemCollectionId.Namespace]
|
||||
var idsByNamespace: [ItemCollectionId.Namespace: Set<ItemCollectionId>]
|
||||
|
||||
init(postbox: Postbox, namespaces: [ItemCollectionId.Namespace]) {
|
||||
self.namespaces = namespaces
|
||||
|
||||
var idsByNamespace: [ItemCollectionId.Namespace: Set<ItemCollectionId>] = [:]
|
||||
for namespace in namespaces {
|
||||
let ids = postbox.itemCollectionInfoTable.getIds(namespace: namespace)
|
||||
idsByNamespace[namespace] = Set(ids)
|
||||
}
|
||||
self.idsByNamespace = idsByNamespace
|
||||
}
|
||||
|
||||
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 {
|
||||
for namespace in self.namespaces {
|
||||
if reloadInfosNamespaces.contains(namespace) {
|
||||
updated = true
|
||||
let ids = postbox.itemCollectionInfoTable.getIds(namespace: namespace)
|
||||
self.idsByNamespace[namespace] = Set(ids)
|
||||
}
|
||||
}
|
||||
}
|
||||
return updated
|
||||
}
|
||||
|
||||
func immutableView() -> PostboxView {
|
||||
return ItemCollectionIdsView(self)
|
||||
}
|
||||
}
|
||||
|
||||
public final class ItemCollectionIdsView: PostboxView {
|
||||
public let idsByNamespace: [ItemCollectionId.Namespace: Set<ItemCollectionId>]
|
||||
|
||||
init(_ view: MutableItemCollectionIdsView) {
|
||||
self.idsByNamespace = view.idsByNamespace
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user