mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 15:17:43 +00:00
Start expiration at end of handling each message type treating call and extraction as DaR
This commit is contained in:
@@ -421,9 +421,10 @@ object MessageSender {
|
||||
storage.markUnidentified(timestamp, userPublicKey)
|
||||
// Start the disappearing messages timer if needed
|
||||
Log.d("MessageSender", "Start the disappearing messages timer if needed message.recipient = ${message.recipient}, userPublicKey = $userPublicKey, isSyncMessage = $isSyncMessage")
|
||||
message.threadID?.let(storage::getExpirationConfiguration)?.takeIf { it.expiryMode.expirySeconds > 0 }?.let { config ->
|
||||
message.threadID?.let(storage::getExpirationConfiguration)?.expiryMode?.takeIf { it.expirySeconds > 0 }?.let { mode ->
|
||||
if (message.recipient == userPublicKey || !isSyncMessage) {
|
||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(timestamp, userPublicKey, timestamp)
|
||||
val expireStartedAt = if (mode is ExpiryMode.AfterRead) timestamp + 1 else timestamp
|
||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(timestamp, userPublicKey, expireStartedAt)
|
||||
}
|
||||
}
|
||||
} ?: run {
|
||||
|
@@ -65,6 +65,8 @@ internal fun MessageReceiver.isBlocked(publicKey: String): Boolean {
|
||||
}
|
||||
|
||||
fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content, threadId: Long, openGroupID: String?) {
|
||||
Log.d("MessageReceiver", "handle() called with: message = $message, proto = $proto, threadId = $threadId, openGroupID = $openGroupID")
|
||||
|
||||
// Do nothing if the message was outdated
|
||||
if (MessageReceiver.messageIsOutdated(message, threadId, openGroupID)) { return }
|
||||
|
||||
@@ -122,6 +124,7 @@ private fun MessageReceiver.handleReadReceipt(message: ReadReceipt) {
|
||||
private fun MessageReceiver.handleCallMessage(message: CallMessage) {
|
||||
// TODO: refactor this out to persistence, just to help debug the flow and send/receive in synchronous testing
|
||||
WebRtcUtils.SIGNAL_QUEUE.trySend(message)
|
||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message, coerceToDisappearAfterRead = true)
|
||||
}
|
||||
|
||||
private fun MessageReceiver.handleTypingIndicator(message: TypingIndicator) {
|
||||
@@ -153,7 +156,7 @@ fun MessageReceiver.cancelTypingIndicatorsIfNeeded(senderPublicKey: String) {
|
||||
}
|
||||
|
||||
private fun MessageReceiver.handleExpirationTimerUpdate(message: ExpirationTimerUpdate) {
|
||||
SSKEnvironment.shared.messageExpirationManager.setExpirationTimer(message)
|
||||
SSKEnvironment.shared.messageExpirationManager.insertExpirationTimerMessage(message)
|
||||
|
||||
if (isNewConfigEnabled) return
|
||||
|
||||
@@ -186,6 +189,7 @@ private fun MessageReceiver.handleDataExtractionNotification(message: DataExtrac
|
||||
else -> return
|
||||
}
|
||||
storage.insertDataExtractionNotificationMessage(senderPublicKey, notification, message.sentTimestamp!!)
|
||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message, coerceToDisappearAfterRead = true)
|
||||
}
|
||||
|
||||
private fun handleConfigurationMessage(message: ConfigurationMessage) {
|
||||
@@ -285,6 +289,8 @@ fun MessageReceiver.handleVisibleMessage(
|
||||
runThreadUpdate: Boolean,
|
||||
runProfileUpdate: Boolean
|
||||
): Long? {
|
||||
Log.d("ReceivedMessageHandler", "handleVisibleMessage() called with: message = $message, proto = $proto, openGroupID = $openGroupID, threadId = $threadId, runThreadUpdate = $runThreadUpdate, runProfileUpdate = $runProfileUpdate")
|
||||
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val context = MessagingModuleConfiguration.shared.context
|
||||
val userPublicKey = storage.getUserPublicKey()
|
||||
@@ -386,14 +392,7 @@ fun MessageReceiver.handleVisibleMessage(
|
||||
}
|
||||
}
|
||||
// Parse attachments if needed
|
||||
val attachments = proto.dataMessage.attachmentsList.mapNotNull { attachmentProto ->
|
||||
val attachment = Attachment.fromProto(attachmentProto)
|
||||
if (!attachment.isValid()) {
|
||||
return@mapNotNull null
|
||||
} else {
|
||||
return@mapNotNull attachment
|
||||
}
|
||||
}
|
||||
val attachments = proto.dataMessage.attachmentsList.map(Attachment::fromProto).filter { it.isValid() }
|
||||
// Cancel any typing indicators if needed
|
||||
cancelTypingIndicatorsIfNeeded(message.sender!!)
|
||||
// Parse reaction if needed
|
||||
@@ -429,6 +428,7 @@ fun MessageReceiver.handleVisibleMessage(
|
||||
val isSms = !message.isMediaMessage() && attachments.isEmpty()
|
||||
storage.setOpenGroupServerMessageID(messageID, it, threadID, isSms)
|
||||
}
|
||||
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message)
|
||||
return messageID
|
||||
}
|
||||
return null
|
||||
|
@@ -1,10 +1,13 @@
|
||||
package org.session.libsession.utilities
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import org.session.libsession.messaging.contacts.Contact
|
||||
import org.session.libsession.messaging.messages.Message
|
||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier
|
||||
import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
|
||||
class SSKEnvironment(
|
||||
@@ -38,8 +41,20 @@ class SSKEnvironment(
|
||||
}
|
||||
|
||||
interface MessageExpirationManagerProtocol {
|
||||
fun setExpirationTimer(message: ExpirationTimerUpdate)
|
||||
fun insertExpirationTimerMessage(message: ExpirationTimerUpdate)
|
||||
fun startAnyExpiration(timestamp: Long, author: String, expireStartedAt: Long)
|
||||
fun startAnyExpiration(message: Message, coerceToDisappearAfterRead: Boolean = false) {
|
||||
Log.d("MessageExpirationManagerProtocol", "startAnyExpiration() called with: message = $message, coerceToDisappearAfterRead = $coerceToDisappearAfterRead")
|
||||
|
||||
val timestamp = message.sentTimestamp ?: return
|
||||
startAnyExpiration(
|
||||
timestamp = timestamp,
|
||||
author = message.sender ?: return,
|
||||
expireStartedAt = if (message.expiryMode is ExpiryMode.AfterRead || coerceToDisappearAfterRead && message.expiryMode.expiryMillis > 0) SnodeAPI.nowWithOffset.coerceAtLeast(timestamp + 1)
|
||||
else if (message.expiryMode is ExpiryMode.AfterSend) timestamp
|
||||
else return
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Reference in New Issue
Block a user