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:
31
submodules/Postbox/Sources/CachedItemView.swift
Normal file
31
submodules/Postbox/Sources/CachedItemView.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import Foundation
|
||||
|
||||
final class MutableCachedItemView: MutablePostboxView {
|
||||
private let id: ItemCacheEntryId
|
||||
fileprivate var value: PostboxCoding?
|
||||
|
||||
init(postbox: Postbox, id: ItemCacheEntryId) {
|
||||
self.id = id
|
||||
self.value = postbox.itemCacheTable.retrieve(id: id, metaTable: postbox.itemCacheMetaTable)
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
|
||||
if transaction.updatedCacheEntryKeys.contains(self.id) {
|
||||
self.value = postbox.itemCacheTable.retrieve(id: id, metaTable: postbox.itemCacheMetaTable)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func immutableView() -> PostboxView {
|
||||
return CachedItemView(self)
|
||||
}
|
||||
}
|
||||
|
||||
public final class CachedItemView: PostboxView {
|
||||
public let value: PostboxCoding?
|
||||
|
||||
init(_ view: MutableCachedItemView) {
|
||||
self.value = view.value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user