mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
53
submodules/Postbox/Sources/PendingMessageActionsView.swift
Normal file
53
submodules/Postbox/Sources/PendingMessageActionsView.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
final class MutablePendingMessageActionsView: MutablePostboxView {
|
||||
let type: PendingMessageActionType
|
||||
var entries: [PendingMessageActionsEntry]
|
||||
|
||||
init(postbox: Postbox, type: PendingMessageActionType) {
|
||||
self.type = type
|
||||
self.entries = postbox.pendingMessageActionsTable.getActions(type: type)
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user