diff --git a/submodules/Postbox/Sources/TimestampBasedMessageAttributesTable.swift b/submodules/Postbox/Sources/TimestampBasedMessageAttributesTable.swift index 8285b09ee2..541cf987e4 100644 --- a/submodules/Postbox/Sources/TimestampBasedMessageAttributesTable.swift +++ b/submodules/Postbox/Sources/TimestampBasedMessageAttributesTable.swift @@ -1,6 +1,6 @@ import Foundation -public struct TimestampBasedMessageAttributesEntry { +public struct TimestampBasedMessageAttributesEntry: CustomStringConvertible { public let tag: UInt16 public let timestamp: Int32 public let messageId: MessageId @@ -8,6 +8,10 @@ public struct TimestampBasedMessageAttributesEntry { public var index: MessageIndex { return MessageIndex(id: self.messageId, timestamp: timestamp) } + + public var description: String { + return "(tag: \(self.tag), timestamp: \(self.timestamp), messageId: \(self.messageId))" + } } enum TimestampBasedMessageAttributesOperation { @@ -53,7 +57,11 @@ final class TimestampBasedMessageAttributesTable: Table { } func set(tag: UInt16, id: MessageId, timestamp: Int32, operations: inout [TimestampBasedMessageAttributesOperation]) { - if let previousTimestamp = self.indexTable.get(tag: tag, id: id) { + let previousTimestamp = self.indexTable.get(tag: tag, id: id) + + postboxLog("TimestampBasedMessageAttributesTable set(tag: \(tag), id: \(id), timestamp: \(timestamp)) previousTimestamp: \(String(describing: previousTimestamp))") + + if let previousTimestamp = previousTimestamp { if previousTimestamp == timestamp { return } else { @@ -67,7 +75,11 @@ final class TimestampBasedMessageAttributesTable: Table { } func remove(tag: UInt16, id: MessageId, operations: inout [TimestampBasedMessageAttributesOperation]) { - if let previousTimestamp = self.indexTable.get(tag: tag, id: id) { + let previousTimestamp = self.indexTable.get(tag: tag, id: id) + + postboxLog("TimestampBasedMessageAttributesTable remove(tag: \(tag), id: \(id)) previousTimestamp: \(String(describing: previousTimestamp))") + + if let previousTimestamp = previousTimestamp { self.valueBox.remove(self.table, key: self.key(tag: tag, timestamp: previousTimestamp, id: id), secure: false) self.indexTable.remove(tag: tag, id: id) operations.append(.remove(TimestampBasedMessageAttributesEntry(tag: tag, timestamp: previousTimestamp, messageId: id))) diff --git a/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift b/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift index bbff66b6d0..a253f1ba23 100644 --- a/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift +++ b/submodules/Postbox/Sources/TimestampBasedMessageAttributesView.swift @@ -7,6 +7,8 @@ final class MutableTimestampBasedMessageAttributesView { init(postbox: Postbox, tag: UInt16) { self.tag = tag self.head = postbox.timestampBasedMessageAttributesTable.head(tag: tag) + + postboxLog("MutableTimestampBasedMessageAttributesView: tag: \(tag) head: \(String(describing: self.head))") } func replay(postbox: Postbox, operations: [TimestampBasedMessageAttributesOperation]) -> Bool { diff --git a/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift b/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift index 6d739dd4a3..ea0c902016 100644 --- a/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift @@ -62,7 +62,9 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe |> distinctUntilChanged*/ let timeOffset: Signal = .single(0.0) - + + Logger.shared.log("Autoremove", "starting isRemove: \(isRemove)") + let disposable = combineLatest(timeOffset, postbox.timestampBasedMessageAttributesView(tag: isRemove ? 0 : 1)).start(next: { timeOffset, view in let (disposeOperations, beginOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(TimestampBasedMessageAttributesEntry, MetaDisposable)]) in return helper.update(view.head)