From 90c2f3742a3c9bf5887468bf1d48aec4d0d45f29 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sun, 9 May 2021 00:38:07 +0400 Subject: [PATCH] [Workaround] Force clear time based attributes for deleted messages --- submodules/Postbox/Sources/Postbox.swift | 9 +++++++++ .../State/ManagedAutoremoveMessageOperations.swift | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/submodules/Postbox/Sources/Postbox.swift b/submodules/Postbox/Sources/Postbox.swift index 699cba0300..1a93b8aee3 100644 --- a/submodules/Postbox/Sources/Postbox.swift +++ b/submodules/Postbox/Sources/Postbox.swift @@ -1096,6 +1096,11 @@ public final class Transaction { assert(!self.disposed) return self.postbox?.searchPeers(query: query) ?? [] } + + public func clearTimestampBasedAttribute(id: MessageId, tag: UInt16) { + assert(!self.disposed) + self.postbox?.clearTimestampBasedAttribute(id: id, tag: tag) + } } public enum PostboxResult { @@ -3565,6 +3570,10 @@ public final class Postbox { } } } + + fileprivate func clearTimestampBasedAttribute(id: MessageId, tag: UInt16) { + self.timestampBasedMessageAttributesTable.remove(tag: tag, id: id, operations: &self.currentTimestampBasedMessageAttributesOperations) + } fileprivate func reindexUnreadCounters() { self.groupMessageStatsTable.removeAll() diff --git a/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift b/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift index ea0c902016..cb3cb92aad 100644 --- a/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift @@ -65,7 +65,9 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe Logger.shared.log("Autoremove", "starting isRemove: \(isRemove)") - let disposable = combineLatest(timeOffset, postbox.timestampBasedMessageAttributesView(tag: isRemove ? 0 : 1)).start(next: { timeOffset, view in + let tag: UInt16 = isRemove ? 0 : 1 + + let disposable = combineLatest(timeOffset, postbox.timestampBasedMessageAttributesView(tag: tag)).start(next: { timeOffset, view in let (disposeOperations, beginOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(TimestampBasedMessageAttributesEntry, MetaDisposable)]) in return helper.update(view.head) } @@ -111,6 +113,7 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe }) } } else { + transaction.clearTimestampBasedAttribute(id: entry.messageId, tag: tag) Logger.shared.log("Autoremove", "No message to autoremove for \(entry.messageId)") } })