mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
48 lines
1.4 KiB
Swift
48 lines
1.4 KiB
Swift
import Foundation
|
|
|
|
final class MutableDeletedMessagesView: MutablePostboxView {
|
|
let peerId: PeerId
|
|
var currentDeletedMessages: [MessageId] = []
|
|
|
|
init(peerId: PeerId) {
|
|
self.peerId = peerId
|
|
}
|
|
|
|
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
|
var updated = false
|
|
if let operations = transaction.currentOperationsByPeerId[self.peerId] {
|
|
var testMessageIds: [MessageId] = []
|
|
for operation in operations {
|
|
switch operation {
|
|
case let .Remove(indices):
|
|
for (index, _) in indices {
|
|
testMessageIds.append(index.id)
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
self.currentDeletedMessages.removeAll()
|
|
for id in testMessageIds {
|
|
if !postbox.messageHistoryIndexTable.exists(id) {
|
|
self.currentDeletedMessages.append(id)
|
|
updated = true
|
|
}
|
|
}
|
|
}
|
|
return updated
|
|
}
|
|
|
|
func immutableView() -> PostboxView {
|
|
return DeletedMessagesView(self)
|
|
}
|
|
}
|
|
|
|
public final class DeletedMessagesView: PostboxView {
|
|
public let currentDeletedMessages: [MessageId]
|
|
|
|
init(_ view: MutableDeletedMessagesView) {
|
|
self.currentDeletedMessages = view.currentDeletedMessages
|
|
}
|
|
}
|