mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
54 lines
1.9 KiB
Swift
54 lines
1.9 KiB
Swift
|
|
final class MutablePendingMessageActionsView: MutablePostboxView {
|
|
let type: PendingMessageActionType
|
|
var entries: [PendingMessageActionsEntry]
|
|
|
|
init(postbox: PostboxImpl, type: PendingMessageActionType) {
|
|
self.type = type
|
|
self.entries = postbox.pendingMessageActionsTable.getActions(type: type)
|
|
}
|
|
|
|
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
|
var updated = false
|
|
for operation in transaction.currentPendingMessageActionsOperations {
|
|
switch operation {
|
|
case let .add(type, id, data):
|
|
if type == self.type {
|
|
var insertIndex = self.entries.count
|
|
while insertIndex > 0 {
|
|
if self.entries[insertIndex - 1].id < id {
|
|
break
|
|
}
|
|
insertIndex -= 1
|
|
}
|
|
self.entries.insert(PendingMessageActionsEntry(id: id, action: data), at: insertIndex)
|
|
updated = true
|
|
}
|
|
case let .remove(type, id):
|
|
if type == self.type {
|
|
loop: for i in 0 ..< self.entries.count {
|
|
if self.entries[i].id == id {
|
|
self.entries.remove(at: i)
|
|
updated = true
|
|
break loop
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return updated
|
|
}
|
|
|
|
func immutableView() -> PostboxView {
|
|
return PendingMessageActionsView(self)
|
|
}
|
|
}
|
|
|
|
public final class PendingMessageActionsView: PostboxView {
|
|
public let entries: [PendingMessageActionsEntry]
|
|
|
|
init(_ view: MutablePendingMessageActionsView) {
|
|
self.entries = view.entries
|
|
}
|
|
}
|