Copy expiryMode from proto for all Messages

This commit is contained in:
Andrew 2024-01-17 00:43:37 +10:30
parent c8377b0e30
commit 1ada072884
16 changed files with 46 additions and 22 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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<QuoteModel> = if (quotes != null) Optional.of(quotes) else Optional.absent()

View File

@ -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 <reified M: Message> 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
}

View File

@ -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
@ -65,6 +66,7 @@ class CallMessage(): ControlMessage() {
val sdpMids = callMessageProto.sdpMidsList
val callId = UUID.fromString(callMessageProto.uuid)
return CallMessage(type, sdps, sdpMLineIndexes, sdpMids, callId)
.copyExpiration(proto)
}
}

View File

@ -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)
}
}

View File

@ -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<ClosedGroup>, 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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}