From ba0ca7d26052e488298032d631e8cf5100d129f4 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 2 Sep 2023 19:53:43 +0930 Subject: [PATCH] Remove Storage#setExpirationTimer --- .../expiration/ExpirationSettingsViewModel.kt | 4 ++-- .../securesms/database/Storage.kt | 24 +------------------ .../service/ExpiringMessageManager.java | 2 -- .../securesms/util/MockDataGenerator.kt | 1 - .../libsession/database/StorageProtocol.kt | 1 - .../messages/ExpirationConfiguration.kt | 2 +- .../ReceivedMessageHandler.kt | 2 -- 7 files changed, 4 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt index debc504de8..3b985c00ed 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt @@ -328,7 +328,7 @@ enum class ExpiryType(private val createMode: (Long) -> ExpiryMode) { AFTER_SEND(ExpiryMode::AfterSend), AFTER_READ(ExpiryMode::AfterRead); - fun mode(seconds: Long) = createMode(seconds) + fun mode(seconds: Long) = if (seconds != 0L) createMode(seconds) else ExpiryMode.NONE fun defaultMode() = when(this) { AFTER_READ -> 12.hours @@ -336,7 +336,7 @@ enum class ExpiryType(private val createMode: (Long) -> ExpiryMode) { }.inWholeSeconds.let(::mode) } -private val ExpiryMode.type: ExpiryType get() = when(this) { +val ExpiryMode.type: ExpiryType get() = when(this) { is ExpiryMode.Legacy -> ExpiryType.LEGACY is ExpiryMode.AfterSend -> ExpiryType.AFTER_SEND is ExpiryMode.AfterRead -> ExpiryType.AFTER_READ 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 8a2fe61dfe..0419b3c384 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -78,6 +78,7 @@ import org.session.libsignal.utilities.IdPrefix import org.session.libsignal.utilities.KeyHelper import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.guava.Optional +import org.thoughtcrime.securesms.conversation.expiration.type import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.database.model.MessageId import org.thoughtcrime.securesms.database.model.ReactionRecord @@ -626,9 +627,6 @@ open class Storage( // Store the encryption key pair val keyPair = ECKeyPair(DjbECPublicKey(group.encPubKey), DjbECPrivateKey(group.encSecKey)) addClosedGroupEncryptionKeyPair(keyPair, group.sessionId, SnodeAPI.nowWithOffset) - // Set expiration timer - val expireTimer = group.disappearingTimer - setExpirationTimer(groupId, expireTimer.toInt()) // Notify the PN server PushRegistryV1.subscribeGroup(group.sessionId, publicKey = localUserPublicKey) // Notify the user @@ -1057,26 +1055,6 @@ open class Storage( .updateTimestampUpdated(groupID, updatedTimestamp) } - override fun setExpirationTimer(address: String, duration: Int) { - val recipient = Recipient.from(context, fromSerialized(address), false) - val threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient) - DatabaseComponent.get(context).expirationConfigurationDatabase().setExpirationConfiguration( - ExpirationConfiguration(threadId, ExpiryMode.AfterSend(duration.toLong()), SnodeAPI.nowWithOffset) - ) - if (recipient.isContactRecipient && !recipient.isLocalNumber) { - configFactory.contacts?.upsertContact(address) { - this.expiryMode = if (duration != 0) { - ExpiryMode.AfterRead(duration.toLong()) - } else { // = 0 / delete - ExpiryMode.NONE - } - } - if (configFactory.contacts?.needsPush() == true) { - ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context) - } - } - } - override fun setServerCapabilities(server: String, capabilities: List) { return DatabaseComponent.get(context).lokiAPIDatabase().setServerCapabilities(server, capabilities) } 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 7801845519..525f2f0dd1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -161,8 +161,6 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM OutgoingExpirationUpdateMessage timerUpdateMessage = new OutgoingExpirationUpdateMessage(recipient, sentTimestamp, duration * 1000L, expireStartedAt, groupId); mmsDatabase.insertSecureDecryptedMessageOutbox(timerUpdateMessage, message.getThreadID(), sentTimestamp, true); - //set the timer to the conversation - MessagingModuleConfiguration.getShared().getStorage().setExpirationTimer(recipient.getAddress().serialize(), duration); } catch (MmsException | IOException ioe) { Log.e("Loki", "Failed to insert expiration update message.", ioe); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/MockDataGenerator.kt b/app/src/main/java/org/thoughtcrime/securesms/util/MockDataGenerator.kt index 691b641a91..712e393f17 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/MockDataGenerator.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/MockDataGenerator.kt @@ -234,7 +234,6 @@ object MockDataGenerator { // Add the group to the user's set of public keys to poll for and store the key pair val encryptionKeyPair = Curve.generateKeyPair() storage.addClosedGroupEncryptionKeyPair(encryptionKeyPair, randomGroupPublicKey, System.currentTimeMillis()) - storage.setExpirationTimer(groupId, 0) storage.createInitialConfigGroup(randomGroupPublicKey, groupName, GroupUtil.createConfigMemberMap(members, setOf(adminUserId)), System.currentTimeMillis(), encryptionKeyPair) // Add the group created message diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt index dbe03c4688..3cbf6a116d 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -152,7 +152,6 @@ interface StorageProtocol { fun getLatestClosedGroupEncryptionKeyPair(groupPublicKey: String): ECKeyPair? fun updateFormationTimestamp(groupID: String, formationTimestamp: Long) fun updateTimestampUpdated(groupID: String, updatedTimestamp: Long) - fun setExpirationTimer(address: String, duration: Int) // Groups fun getAllGroups(includeInactive: Boolean): List diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt index 5fd186622c..696f27799b 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt @@ -17,4 +17,4 @@ data class ExpirationConfiguration( data class ExpirationDatabaseMetadata( val threadId: Long = -1, val updatedTimestampMs: Long -) \ No newline at end of file +) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt index 9201390df1..4fd9d7427c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt @@ -650,8 +650,6 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli // Store the encryption key pair storage.addClosedGroupEncryptionKeyPair(encryptionKeyPair, groupPublicKey, sentTimestamp) storage.createInitialConfigGroup(groupPublicKey, name, GroupUtil.createConfigMemberMap(members, admins), formationTimestamp, encryptionKeyPair) - // Set expiration timer - storage.setExpirationTimer(groupID, expireTimer) // Notify the PN server PushRegistryV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey) // Notify the user