Fix disappear after read

This commit is contained in:
Andrew
2024-01-11 12:34:41 +10:30
parent 6fbae28d70
commit 7b26de5bd6
9 changed files with 55 additions and 80 deletions

View File

@@ -13,7 +13,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
*
* **Note:** `nil` if this isn't a sync message.
*/
class VisibleMessage(
data class VisibleMessage(
var syncTarget: String? = null,
var text: String? = null,
val attachmentIDs: MutableList<Long> = mutableListOf(),

View File

@@ -68,7 +68,6 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
// Do nothing if the message was outdated
if (MessageReceiver.messageIsOutdated(message, threadId, openGroupID)) { return }
MessageReceiver.updateExpiryIfNeeded(message, proto, openGroupID)
when (message) {
is ReadReceipt -> handleReadReceipt(message)
is TypingIndicator -> handleTypingIndicator(message)
@@ -154,7 +153,9 @@ fun MessageReceiver.cancelTypingIndicatorsIfNeeded(senderPublicKey: String) {
}
private fun MessageReceiver.handleExpirationTimerUpdate(message: ExpirationTimerUpdate) {
if (ExpirationConfiguration.isNewConfigEnabled) return
SSKEnvironment.shared.messageExpirationManager.setExpirationTimer(message)
if (isNewConfigEnabled) return
val module = MessagingModuleConfiguration.shared
try {
@@ -171,7 +172,6 @@ private fun MessageReceiver.handleExpirationTimerUpdate(message: ExpirationTimer
} catch (e: Exception) {
Log.e("Loki", "Failed to update expiration configuration.")
}
SSKEnvironment.shared.messageExpirationManager.setExpirationTimer(message)
}
private fun MessageReceiver.handleDataExtractionNotification(message: DataExtractionNotification) {
@@ -269,58 +269,6 @@ fun handleMessageRequestResponse(message: MessageRequestResponse) {
}
//endregion
fun MessageReceiver.updateExpiryIfNeeded(
message: Message,
proto: SignalServiceProtos.Content,
openGroupID: String?
) {
val storage = MessagingModuleConfiguration.shared.storage
val sentTime = message.sentTimestamp ?: throw MessageReceiver.Error.InvalidMessage
val threadID =
storage.getThreadIdFor(message.sender!!, message.groupPublicKey, openGroupID, false)
?: throw MessageReceiver.Error.NoThread
val recipient = storage.getRecipientForThread(threadID) ?: throw MessageReceiver.Error.NoThread
if (!recipient.isLocalNumber) {
val disappearingState = if (proto.hasExpirationType()) Recipient.DisappearingState.UPDATED else Recipient.DisappearingState.LEGACY
storage.updateDisappearingState(message.sender!!, threadID, disappearingState)
}
if (!proto.hasLastDisappearingMessageChangeTimestamp() && !isNewConfigEnabled) return
val localConfig = storage.getExpirationConfiguration(threadID)
val durationSeconds = if (proto.hasExpirationTimer()) proto.expirationTimer else 0
val type = if (proto.hasExpirationType()) proto.expirationType else null
val expiryMode = type?.expiryMode(durationSeconds.toLong()) ?: ExpiryMode.NONE
val lastDisappearingMessageChangeTimestamp = proto.lastDisappearingMessageChangeTimestamp
// don't update any values for open groups
if (recipient.isOpenGroupRecipient && type != null) throw MessageReceiver.Error.InvalidMessage
val incoming1on1 = recipient.isContactRecipient && !message.isSenderSelf
val remoteConfig = ExpirationConfiguration(
threadID,
expiryMode,
lastDisappearingMessageChangeTimestamp
)
remoteConfig.takeUnless { incoming1on1 }?.takeIf {
localConfig == null
|| it.updatedTimestampMs > localConfig.updatedTimestampMs
|| !isNewConfigEnabled && !proto.hasLastDisappearingMessageChangeTimestamp()
}?.let(storage::setExpirationConfiguration)
if (message is ExpirationTimerUpdate) {
SSKEnvironment.shared.messageExpirationManager.setExpirationTimer(message)
}
}
private fun SignalServiceProtos.Content.ExpirationType.expiryMode(durationSeconds: Long) = takeIf { durationSeconds > 0 }?.let {
when (it) {
SignalServiceProtos.Content.ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(durationSeconds)
@@ -465,14 +413,10 @@ fun MessageReceiver.handleVisibleMessage(
// Persist the message
message.threadID = threadID
val messageID =
storage.persist(message, quoteModel, linkPreviews, message.groupPublicKey, openGroupID,
attachments, runThreadUpdate
) ?: return null
val openGroupServerID = message.openGroupServerMessageID
if (openGroupServerID != null) {
val isSms = !(message.isMediaMessage() || attachments.isNotEmpty())
storage.setOpenGroupServerMessageID(messageID, openGroupServerID, threadID, isSms)
val messageID = storage.persist(message, quoteModel, linkPreviews, message.groupPublicKey, openGroupID, attachments, runThreadUpdate) ?: return null
message.openGroupServerMessageID?.let {
val isSms = !message.isMediaMessage() && attachments.isEmpty()
storage.setOpenGroupServerMessageID(messageID, it, threadID, isSms)
}
return messageID
}

View File

@@ -1,6 +1,7 @@
package org.session.libsession.messaging.utilities
import android.content.Context
import android.util.Log
import org.session.libsession.R
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.calls.CallMessageType
@@ -17,6 +18,8 @@ import org.session.libsession.utilities.recipients.Recipient
import org.session.libsession.utilities.truncateIdForDisplay
object UpdateMessageBuilder {
private val TAG = "UpdateMessageBuilder"
val storage = MessagingModuleConfiguration.shared.storage
private fun getSenderName(senderId: String) = storage.getContactWithSessionID(senderId)
@@ -85,6 +88,8 @@ object UpdateMessageBuilder {
timestamp: Long,
expireStarted: Long
): String {
Log.d(TAG, "buildExpirationTimerMessage() called with: duration = $duration, senderId = $senderId, isOutgoing = $isOutgoing, timestamp = $timestamp, expireStarted = $expireStarted")
if (!isOutgoing && senderId == null) return ""
val senderName = if (isOutgoing) context.getString(R.string.MessageRecord_you) else getSenderName(senderId!!)
return if (duration <= 0) {
@@ -98,6 +103,7 @@ object UpdateMessageBuilder {
} else {
val time = ExpirationUtil.getExpirationDisplayValue(context, duration.toInt())
val action = context.getExpirationTypeDisplayValue(timestamp == expireStarted)
Log.d(TAG, "action = $action because timestamp = $timestamp and expireStarted = $expireStarted equal = ${timestamp == expireStarted}")
if (isOutgoing) {
if (!isNewConfigEnabled) context.getString(R.string.MessageRecord_you_set_disappearing_message_time_to_s, time)
else context.getString(
@@ -114,7 +120,7 @@ object UpdateMessageBuilder {
action
)
}
}
}.also { Log.d(TAG, "display: $it") }
}
fun buildDataExtractionMessage(context: Context, kind: DataExtractionNotificationInfoMessage.Kind, senderId: String? = null): String {