From 9ca6986b715fbd6bbc6f38889f47e60c8fef72cd Mon Sep 17 00:00:00 2001 From: Brice-W Date: Tue, 6 Apr 2021 16:05:59 +1000 Subject: [PATCH] fix sync of expiration timer update messages between linked devices --- .../conversation/ConversationActivity.java | 2 +- .../messages/control/ExpirationTimerUpdate.kt | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 6301ec6b56..3cceeb089c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -806,7 +806,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override protected Void doInBackground(Void... params) { DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setExpireMessages(recipient, expirationTime); - ExpirationTimerUpdate message = new ExpirationTimerUpdate(expirationTime); + ExpirationTimerUpdate message = new ExpirationTimerUpdate(null, expirationTime); message.setSentTimestamp(System.currentTimeMillis()); OutgoingExpirationUpdateMessage outgoingMessage = OutgoingExpirationUpdateMessage.from(message, recipient); try { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt index 1473146237..85f34eed51 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ExpirationTimerUpdate.kt @@ -7,6 +7,8 @@ import org.session.libsignal.service.internal.push.SignalServiceProtos class ExpirationTimerUpdate() : ControlMessage() { + /// In the case of a sync message, the public key of the person the message was targeted at. + /// - Note: `nil` if this isn't a sync message. var syncTarget: String? = null var duration: Int? = 0 @@ -19,13 +21,15 @@ class ExpirationTimerUpdate() : ControlMessage() { val dataMessageProto = if (proto.hasDataMessage()) proto.dataMessage else return null val isExpirationTimerUpdate = dataMessageProto.flags.and(SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0 if (!isExpirationTimerUpdate) return null + val syncTarget = dataMessageProto.syncTarget val duration = dataMessageProto.expireTimer - return ExpirationTimerUpdate(duration) + return ExpirationTimerUpdate(syncTarget, duration) } } //constructor - internal constructor(duration: Int) : this() { + internal constructor(syncTarget: String?, duration: Int) : this() { + this.syncTarget = syncTarget this.duration = duration } @@ -44,7 +48,10 @@ class ExpirationTimerUpdate() : ControlMessage() { val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder() dataMessageProto.flags = SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE dataMessageProto.expireTimer = duration - syncTarget?.let { dataMessageProto.syncTarget = it } + // Sync target + if (syncTarget != null) { + dataMessageProto.syncTarget = syncTarget + } // Group context if (MessagingConfiguration.shared.storage.isClosedGroup(recipient!!)) { try {