From 4a8ce784b84c047791bbe76d1e0474bd88e844da Mon Sep 17 00:00:00 2001 From: Harris Date: Fri, 28 May 2021 10:50:07 +1000 Subject: [PATCH] fix: no longer using the wrong deletion IDs for open group deletions --- .../messaging/open_groups/OpenGroupAPIV2.kt | 13 ++++--------- .../sending_receiving/pollers/OpenGroupPollerV2.kt | 10 +++++----- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPIV2.kt b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPIV2.kt index a1bcfe441c..ed8c9fa05a 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPIV2.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPIV2.kt @@ -17,14 +17,9 @@ import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPolle import org.session.libsession.snode.OnionRequestAPI import org.session.libsession.utilities.AESGCM import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.utilities.HTTP -import org.session.libsignal.utilities.HTTP.Verb.* -import org.session.libsignal.utilities.removing05PrefixIfNeeded -import org.session.libsignal.utilities.toHexString +import org.session.libsignal.utilities.* import org.session.libsignal.utilities.Base64.* -import org.session.libsignal.utilities.Hex -import org.session.libsignal.utilities.JsonUtil -import org.session.libsignal.utilities.Log +import org.session.libsignal.utilities.HTTP.Verb.* import org.whispersystems.curve25519.Curve25519 import java.util.* @@ -63,7 +58,7 @@ object OpenGroupAPIV2 { @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class) data class CompactPollRequest(val roomID: String, val authToken: String, val fromDeletionServerID: Long?, val fromMessageServerID: Long?) - data class CompactPollResult(val messages: List, val deletions: List, val moderators: List) + data class CompactPollResult(val messages: List, val deletions: List, val moderators: List) @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class) data class MessageDeletion @@ -402,7 +397,7 @@ object OpenGroupAPIV2 { val messages = parseMessages(roomID, server, rawMessages) roomID to CompactPollResult( messages = messages, - deletions = deletedServerIDs.map { it.deletedMessageId }, + deletions = deletedServerIDs, moderators = moderators ) }.toMap() diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt index 57ec540da9..3fe4ac525c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPollerV2.kt @@ -97,15 +97,15 @@ class OpenGroupPollerV2(private val server: String, private val executorService: JobQueue.shared.add(TrimThreadJob(threadId)) } - private fun handleDeletedMessages(room: String, openGroupID: String, deletedMessageServerIDs: List) { + private fun handleDeletedMessages(room: String, openGroupID: String, deletedMessages: List) { val storage = MessagingModuleConfiguration.shared.storage val dataProvider = MessagingModuleConfiguration.shared.messageDataProvider val groupID = GroupUtil.getEncodedOpenGroupID(openGroupID.toByteArray()) val threadID = storage.getThreadId(Address.fromSerialized(groupID)) ?: return - val deletedMessageIDs = deletedMessageServerIDs.mapNotNull { serverID -> - val messageID = dataProvider.getMessageID(serverID, threadID) + val deletedMessageIDs = deletedMessages.mapNotNull { deletion -> + val messageID = dataProvider.getMessageID(deletion.deletedMessageId, threadID) if (messageID == null) { - Log.d("Loki", "Couldn't find message ID for message with serverID: $serverID.") + Log.d("Loki", "Couldn't find message ID for message with serverID: ${deletion.deletedMessageId}.") } messageID } @@ -113,7 +113,7 @@ class OpenGroupPollerV2(private val server: String, private val executorService: MessagingModuleConfiguration.shared.messageDataProvider.deleteMessage(messageId, isSms) } val currentMax = storage.getLastDeletionServerID(room, server) ?: 0L - val latestMax = deletedMessageServerIDs.maxOrNull() ?: 0L + val latestMax = deletedMessages.map { it.id }.maxOrNull() ?: 0L if (latestMax > currentMax && latestMax != 0L) { storage.setLastDeletionServerID(room, server, latestMax) }