mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Stories
This commit is contained in:
52
submodules/Postbox/Sources/StoryView.swift
Normal file
52
submodules/Postbox/Sources/StoryView.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
import Foundation
|
||||
|
||||
final class MutableStoryView: MutablePostboxView {
|
||||
let id: StoryId
|
||||
var item: CodableEntry?
|
||||
|
||||
init(postbox: PostboxImpl, id: StoryId) {
|
||||
self.id = id
|
||||
self.item = postbox.storyTable.get(id: self.id)
|
||||
}
|
||||
|
||||
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
||||
var updated = false
|
||||
|
||||
for event in transaction.storyEvents {
|
||||
switch event {
|
||||
case .updated(self.id):
|
||||
let item = postbox.storyTable.get(id: self.id)
|
||||
if self.item != item {
|
||||
self.item = item
|
||||
updated = true
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return updated
|
||||
}
|
||||
|
||||
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool {
|
||||
let item = postbox.storyTable.get(id: self.id)
|
||||
if self.item != item {
|
||||
self.item = item
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func immutableView() -> PostboxView {
|
||||
return StoryView(self)
|
||||
}
|
||||
}
|
||||
|
||||
public final class StoryView: PostboxView {
|
||||
public let item: CodableEntry?
|
||||
|
||||
init(_ view: MutableStoryView) {
|
||||
self.item = view.item
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user