mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Copy expiryMode from proto for all Messages
This commit is contained in:
parent
c8377b0e30
commit
1ada072884
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user