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 a2860aef10..fa08825edd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -750,13 +750,18 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val recipient = Recipient.from(context, address, false) if (recipient.isBlocked) return - + 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 mediaMessage = IncomingMediaMessage( address, sentTimestamp, -1, - 0, - 0, + expiresInMillis, + expireStartedAt, false, false, false, @@ -770,6 +775,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, ) database.insertSecureDecryptedMessageInbox(mediaMessage, -1, runIncrement = true, runThreadUpdate = true) + SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(sentTimestamp, senderPublicKey, expireStartedAt) } override fun insertMessageRequestResponse(response: MessageRequestResponse) { @@ -825,13 +831,17 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, } recipientDb.setApproved(sender, true) recipientDb.setApprovedMe(sender, true) - + val expirationConfig = getExpirationConfiguration(threadId) + val expiresInMillis = (expirationConfig?.durationSeconds ?: 0) * 100L + val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { + response.sentTimestamp!! + } else 0 val message = IncomingMediaMessage( sender.address, response.sentTimestamp!!, -1, - 0, - 0, + expiresInMillis, + expireStartedAt, false, false, true, 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 5e52d164ff..f5f8b12c65 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -95,7 +95,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM String senderPublicKey = message.getSender(); Long sentTimestamp = message.getSentTimestamp(); String groupId = message.getGroupPublicKey(); - int duration = message.getDuration(); + long expiresInMillis = message.getDuration() * 1000L; Optional groupInfo = Optional.absent(); Address address = Address.fromSerialized(senderPublicKey); @@ -114,7 +114,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM } IncomingMediaMessage mediaMessage = new IncomingMediaMessage(address, sentTimestamp, -1, - duration * 1000L, expireStartedAt, true, + expiresInMillis, expireStartedAt, true, false, false, Optional.absent(),