From 03766d57ee455b888af608800978009f243027f3 Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 22 Dec 2022 14:18:40 +1100 Subject: [PATCH] Disappear after read info refactor --- .../securesms/database/MmsDatabase.kt | 1 - .../securesms/database/SmsDatabase.java | 8 ++-- .../securesms/database/Storage.kt | 40 +++++++++---------- .../service/ExpiringMessageManager.java | 6 +-- .../sending_receiving/MessageSender.kt | 2 +- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt index 32fe4d09db..da9ec1ec30 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt @@ -668,7 +668,6 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa contentValues.put(SUBSCRIPTION_ID, retrieved.subscriptionId) contentValues.put(EXPIRES_IN, retrieved.expiresIn) contentValues.put(EXPIRE_STARTED, retrieved.expireStartedAt) - contentValues.put(READ, if (retrieved.isExpirationUpdate) 1 else 0) contentValues.put(UNIDENTIFIED, retrieved.isUnidentified) contentValues.put(MESSAGE_REQUEST_RESPONSE, retrieved.isMessageRequestResponse) if (!contentValues.containsKey(DATE_SENT)) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java index 114961f42e..25abddec7b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -332,12 +332,10 @@ public class SmsDatabase extends MessagingDatabase { cursor = database.query(TABLE_NAME, new String[] {ID, ADDRESS, DATE_SENT, TYPE, EXPIRES_IN, EXPIRE_STARTED}, where, arguments, null, null, null); while (cursor != null && cursor.moveToNext()) { - if (Types.isSecureType(cursor.getLong(3))) { - SyncMessageId syncMessageId = new SyncMessageId(Address.fromSerialized(cursor.getString(1)), cursor.getLong(2)); - ExpirationInfo expirationInfo = new ExpirationInfo(cursor.getLong(0), cursor.getLong(4), cursor.getLong(5), false); + SyncMessageId syncMessageId = new SyncMessageId(Address.fromSerialized(cursor.getString(1)), cursor.getLong(2)); + ExpirationInfo expirationInfo = new ExpirationInfo(cursor.getLong(0), cursor.getLong(4), cursor.getLong(5), false); - results.add(new MarkedMessageInfo(syncMessageId, expirationInfo)); - } + results.add(new MarkedMessageInfo(syncMessageId, expirationInfo)); } ContentValues contentValues = new ContentValues(); 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 fa08825edd..7c31263cfa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -160,9 +160,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, } val expirationConfig = getExpirationConfiguration(message.threadID ?: -1) val expiresInMillis = (expirationConfig?.durationSeconds ?: 0) * 1000L - val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - message.sentTimestamp!! - } else 0 + val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) message.sentTimestamp!! else 0 if (message.isMediaMessage() || attachments.isNotEmpty()) { val quote: Optional = if (quotes != null) Optional.of(quotes) else Optional.absent() val linkPreviews: Optional> = if (linkPreview.isEmpty()) Optional.absent() else Optional.of(linkPreview.mapNotNull { it!! }) @@ -212,7 +210,9 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, DatabaseComponent.get(context).lokiMessageDatabase().setMessageServerHash(id, serverHash) } } - SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, message.sender!!, expireStartedAt) + if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, message.sender!!, expireStartedAt) + } return messageID } @@ -483,15 +483,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient) val expirationConfig = getExpirationConfiguration(threadId) val expiresInMillis = (expirationConfig?.durationSeconds ?: 0) * 100L - val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - sentTimestamp - } else 0 + val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) sentTimestamp else 0 val m = IncomingTextMessage(fromSerialized(senderPublicKey), 1, sentTimestamp, "", Optional.of(group), expiresInMillis, expireStartedAt, true) val updateData = UpdateMessageData.buildGroupUpdate(type, name, members)?.toJSON() val infoMessage = IncomingGroupMessage(m, groupID, updateData, true) val smsDB = DatabaseComponent.get(context).smsDatabase() smsDB.insertMessageInbox(infoMessage, true, true) - SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) + if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) + } } override fun insertOutgoingInfoMessage(context: Context, groupID: String, type: SignalServiceGroup.Type, name: String, members: Collection, admins: Collection, threadID: Long, sentTimestamp: Long) { @@ -500,9 +500,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient) val expirationConfig = getExpirationConfiguration(threadId) val expiresInMillis = (expirationConfig?.durationSeconds ?: 0) * 100L - val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - sentTimestamp - } else 0 + val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) sentTimestamp else 0 val updateData = UpdateMessageData.buildGroupUpdate(type, name, members)?.toJSON() ?: "" val infoMessage = OutgoingGroupMediaMessage(recipient, updateData, groupID, null, sentTimestamp, expiresInMillis, expireStartedAt, true, null, listOf(), listOf()) val mmsDB = DatabaseComponent.get(context).mmsDatabase() @@ -510,7 +508,9 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, if (mmsSmsDB.getMessageFor(sentTimestamp, userPublicKey) != null) return val infoMessageID = mmsDB.insertMessageOutbox(infoMessage, threadID, false, null, runThreadUpdate = true) mmsDB.markAsSent(infoMessageID, true) - SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, userPublicKey!!, expireStartedAt) + if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, userPublicKey!!, expireStartedAt) + } } override fun isClosedGroup(publicKey: String): Boolean { @@ -753,9 +753,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient) val expirationConfig = getExpirationConfiguration(threadId) val expiresInMillis = (expirationConfig?.durationSeconds ?: 0) * 100L - val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - sentTimestamp - } else 0 + val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) sentTimestamp else 0 val mediaMessage = IncomingMediaMessage( address, sentTimestamp, @@ -775,7 +773,9 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, ) database.insertSecureDecryptedMessageInbox(mediaMessage, -1, runIncrement = true, runThreadUpdate = true) - SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) + if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) + } } override fun insertMessageRequestResponse(response: MessageRequestResponse) { @@ -872,12 +872,12 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient) val expirationConfig = getExpirationConfiguration(threadId) val expiresInMillis = (expirationConfig?.durationSeconds ?: 0) * 100L - val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - sentTimestamp - } else 0 + val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) sentTimestamp else 0 val callMessage = IncomingTextMessage.fromCallInfo(callMessageType, address, Optional.absent(), sentTimestamp, expiresInMillis, expireStartedAt) database.insertCallMessage(callMessage) - SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) + if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) + } } override fun conversationHasOutgoing(userPublicKey: String): Boolean { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java index f5f8b12c65..d7eb563e8f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -71,8 +71,8 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM public void setExpirationTimer(@NotNull ExpirationTimerUpdate message, int expiryType) { String userPublicKey = TextSecurePreferences.getLocalNumber(context); String senderPublicKey = message.getSender(); - long expireStartedAt = ExpirationType.DELETE_AFTER_SEND_VALUE != expiryType - ? 0 : message.getSentTimestamp(); + long expireStartedAt = expiryType == ExpirationType.DELETE_AFTER_SEND_VALUE + ? message.getSentTimestamp() : 0; // Notify the user if (senderPublicKey == null || userPublicKey.equals(senderPublicKey)) { @@ -81,7 +81,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM } else { insertIncomingExpirationTimerMessage(message, expireStartedAt); } - if (message.getSentTimestamp() != null && senderPublicKey != null) { + if (expiryType == ExpirationType.DELETE_AFTER_SEND_VALUE && message.getSentTimestamp() != null && senderPublicKey != null) { startAnyExpiration(message.getSentTimestamp(), senderPublicKey, expireStartedAt); } if (message.getId() != null) { diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index b23511d7fb..89c8244db2 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -380,7 +380,7 @@ object MessageSender { storage.markAsSent(message.sentTimestamp!!, userPublicKey) storage.markUnidentified(message.sentTimestamp!!, userPublicKey) // Start the disappearing messages timer if needed - if (message is VisibleMessage && !isSyncMessage) { + if (!isSyncMessage) { SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, userPublicKey, System.currentTimeMillis()) } } ?: run {