diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt index ed4fe5defd..a64e718808 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt @@ -29,7 +29,8 @@ class DisappearingMessages @Inject constructor( val expiryChangeTimestampMs = SnodeAPI.nowWithOffset MessagingModuleConfiguration.shared.storage.setExpirationConfiguration(ExpirationConfiguration(threadId, mode, expiryChangeTimestampMs)) - val message = ExpirationTimerUpdate(mode).apply { + val message = ExpirationTimerUpdate().apply { + expiryMode = mode sender = textSecurePreferences.getLocalNumber() isSenderSelf = true recipient = address.serialize() diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesViewModel.kt index fce6b96613..f3ed76f06b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesViewModel.kt @@ -93,7 +93,8 @@ class DisappearingMessagesViewModel( val expiryChangeTimestampMs = SnodeAPI.nowWithOffset storage.setExpirationConfiguration(ExpirationConfiguration(threadId, mode, expiryChangeTimestampMs)) - val message = ExpirationTimerUpdate(mode).apply { + val message = ExpirationTimerUpdate().apply { + expiryMode = mode sender = textSecurePreferences.getLocalNumber() isSenderSelf = true recipient = address.serialize() diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index a5fe028e65..090a7a2d0c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -273,7 +273,6 @@ class VisibleMessageView : LinearLayout { binding.messageStatusImageView.isVisible = iconID != null && !showTimer && (!message.isSent || isLastMessage) - binding.messageStatusImageView.bringToFront() binding.expirationTimerView.bringToFront() binding.expirationTimerView.isVisible = showTimer diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 7fee136003..f37f9b5b63 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -331,9 +331,8 @@ open class Storage( // open group recipients should explicitly create threads message.threadID = getOrCreateThreadIdFor(targetAddress) } - val expirationConfig = getExpirationConfiguration(message.threadID ?: -1) - val expiryMode = expirationConfig?.expiryMode - val expiresInMillis = expiryMode?.expiryMillis ?: 0 + val expiryMode = message.expiryMode + val expiresInMillis = expiryMode.expiryMillis val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) message.sentTimestamp!! else 0 if (message.isMediaMessage() || attachments.isNotEmpty()) { val quote: Optional = if (quotes != null) Optional.of(quotes) else Optional.absent() diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt index bfd5508643..6a325d81fb 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt @@ -23,6 +23,8 @@ abstract class Message { var serverHash: String? = null var specifiedTtl: Long? = null + var expiryMode: ExpiryMode = ExpiryMode.NONE + open val defaultTtl: Long = 14 * 24 * 60 * 60 * 1000 open val ttl: Long get() = specifiedTtl ?: defaultTtl open val isSelfSendValid: Boolean = false @@ -75,3 +77,15 @@ abstract class Message { return this } } + +inline fun M.copyExpiration(proto: SignalServiceProtos.Content): M { + val duration: Int = (if (proto.hasExpirationTimer()) proto.expirationTimer else if (proto.hasDataMessage()) proto.dataMessage?.expireTimer else null) ?: return this + + expiryMode = when (proto.expirationType.takeIf { duration > 0 }) { + ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong()) + ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(duration.toLong()) + else -> ExpiryMode.NONE + } + + return this +} diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/CallMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/CallMessage.kt index ec7cade1e1..4ef15367d6 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/CallMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/CallMessage.kt @@ -1,5 +1,6 @@ package org.session.libsession.messaging.messages.control +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.protos.SignalServiceProtos.CallMessage.Type.* import org.session.libsignal.utilities.Log @@ -64,7 +65,8 @@ class CallMessage(): ControlMessage() { val sdpMLineIndexes = callMessageProto.sdpMLineIndexesList val sdpMids = callMessageProto.sdpMidsList val callId = UUID.fromString(callMessageProto.uuid) - return CallMessage(type,sdps, sdpMLineIndexes, sdpMids, callId) + return CallMessage(type, sdps, sdpMLineIndexes, sdpMids, callId) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt index 67f94768e1..41340d6e88 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt @@ -2,6 +2,7 @@ package org.session.libsession.messaging.messages.control import com.google.protobuf.ByteString import org.session.libsession.messaging.MessagingModuleConfiguration +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsession.utilities.Address import org.session.libsignal.crypto.ecc.DjbECPrivateKey import org.session.libsignal.crypto.ecc.DjbECPublicKey @@ -118,6 +119,7 @@ class ClosedGroupControlMessage() : ControlMessage() { } } return ClosedGroupControlMessage(kind) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ConfigurationMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ConfigurationMessage.kt index cadfd07443..5a3db978ce 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ConfigurationMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ConfigurationMessage.kt @@ -2,6 +2,7 @@ package org.session.libsession.messaging.messages.control import com.google.protobuf.ByteString import org.session.libsession.messaging.MessagingModuleConfiguration +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsession.utilities.Address import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.ProfileKeyUtil @@ -159,6 +160,7 @@ class ConfigurationMessage(var closedGroups: List, var openGroups: val profileKey = configurationProto.profileKey val contacts = configurationProto.contactsList.mapNotNull { Contact.fromProto(it) } return ConfigurationMessage(closedGroups, openGroups, contacts, displayName, profilePicture, profileKey.toByteArray()) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt index 9bea2fbcc4..bfe3c92cba 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/DataExtractionNotification.kt @@ -1,5 +1,6 @@ package org.session.libsession.messaging.messages.control +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -31,6 +32,7 @@ class DataExtractionNotification() : ControlMessage() { } } return DataExtractionNotification(kind) + .copyExpiration(proto) } } 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 2584583734..ec50d409c4 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 @@ -2,7 +2,7 @@ package org.session.libsession.messaging.messages.control import network.loki.messenger.libsession_util.util.ExpiryMode import org.session.libsession.messaging.MessagingModuleConfiguration -import org.session.libsession.messaging.messages.ExpirationConfiguration +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsession.messaging.messages.visible.VisibleMessage import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -11,8 +11,7 @@ import org.session.libsignal.utilities.Log * * **Note:** `nil` if this isn't a sync message. */ -data class ExpirationTimerUpdate(var expiryMode: ExpiryMode, var syncTarget: String? = null) : ControlMessage() { - +data class ExpirationTimerUpdate(var syncTarget: String? = null) : ControlMessage() { override val isSelfSendValid: Boolean = true companion object { @@ -24,16 +23,9 @@ data class ExpirationTimerUpdate(var expiryMode: ExpiryMode, var syncTarget: Str SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE ) != 0 if (!isExpirationTimerUpdate) return null - val syncTarget = dataMessageProto.syncTarget - val duration: Int = if (proto.hasExpirationTimer()) proto.expirationTimer else dataMessageProto.expireTimer - val type = proto.expirationType.takeIf { duration > 0 } - val expiryMode = when (type) { - SignalServiceProtos.Content.ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong()) - SignalServiceProtos.Content.ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(duration.toLong()) - else -> duration.takeIf { it > 0 }?.toLong()?.let(ExpiryMode::AfterSend) ?: ExpiryMode.NONE - } - return ExpirationTimerUpdate(expiryMode, syncTarget) + return ExpirationTimerUpdate(dataMessageProto.syncTarget) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/MessageRequestResponse.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/MessageRequestResponse.kt index 65c7d9abd2..57e6cff29d 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/MessageRequestResponse.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/MessageRequestResponse.kt @@ -1,6 +1,7 @@ package org.session.libsession.messaging.messages.control import com.google.protobuf.ByteString +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsession.messaging.messages.visible.Profile import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -41,7 +42,7 @@ class MessageRequestResponse(val isApproved: Boolean, var profile: Profile? = nu profilePictureURL = profileProto.profilePicture } return MessageRequestResponse(isApproved, profile) + .copyExpiration(proto) } } - -} \ No newline at end of file +} diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt index 881117019b..9cfb3bbc52 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ReadReceipt.kt @@ -1,5 +1,6 @@ package org.session.libsession.messaging.messages.control +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -22,6 +23,7 @@ class ReadReceipt() : ControlMessage() { val timestamps = receiptProto.timestampList if (timestamps.isEmpty()) return null return ReadReceipt(timestamps = timestamps) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/SharedConfigurationMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/SharedConfigurationMessage.kt index 72b2474965..f904c7f07c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/SharedConfigurationMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/SharedConfigurationMessage.kt @@ -1,6 +1,7 @@ package org.session.libsession.messaging.messages.control import com.google.protobuf.ByteString +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage @@ -15,6 +16,7 @@ class SharedConfigurationMessage(val kind: SharedConfigMessage.Kind, val data: B val sharedConfig = proto.sharedConfigMessage if (!sharedConfig.hasKind() || !sharedConfig.hasData()) return null return SharedConfigurationMessage(sharedConfig.kind, sharedConfig.data.toByteArray(), sharedConfig.seqno) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt index be99e5ec7a..bfb1b7554d 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/TypingIndicator.kt @@ -1,5 +1,6 @@ package org.session.libsession.messaging.messages.control +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -20,6 +21,7 @@ class TypingIndicator() : ControlMessage() { val typingIndicatorProto = if (proto.hasTypingMessage()) proto.typingMessage else return null val kind = Kind.fromProto(typingIndicatorProto.action) return TypingIndicator(kind = kind) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/UnsendRequest.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/UnsendRequest.kt index 74966bd5cd..301503cef7 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/UnsendRequest.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/UnsendRequest.kt @@ -1,5 +1,6 @@ package org.session.libsession.messaging.messages.control +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -24,6 +25,7 @@ class UnsendRequest(): ControlMessage() { val timestamp = unsendRequestProto.timestamp val author = unsendRequestProto.author return UnsendRequest(timestamp, author) + .copyExpiration(proto) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt index a2c63cdce2..04ceeb66ef 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt @@ -3,6 +3,7 @@ package org.session.libsession.messaging.messages.visible import com.goterl.lazysodium.BuildConfig import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.messages.Message +import org.session.libsession.messaging.messages.copyExpiration import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment import org.session.libsignal.protos.SignalServiceProtos import org.session.libsignal.utilities.Log @@ -75,7 +76,7 @@ data class VisibleMessage( result.blocksMessageRequests = with (dataMessage) { hasBlocksCommunityMessageRequests() && blocksCommunityMessageRequests } - return result + return result.copyExpiration(proto) } }