mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
65
submodules/Postbox/Sources/ItemCollectionInfoView.swift
Normal file
65
submodules/Postbox/Sources/ItemCollectionInfoView.swift
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user