From f7b8a90edbbf97ab91bc7acedca566a8e485db30 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Wed, 17 May 2023 11:58:47 +1000 Subject: [PATCH] fix: some compile issues in tests and some TODOs for things to do before merge --- .../v2/messages/VisibleMessageContentView.kt | 3 +-- .../database/helpers/SQLCipherOpenHelper.java | 1 + .../service/ExpiringMessageManager.java | 23 +++++++++---------- .../v2/ConversationViewModelTest.kt | 3 +-- .../MessageRequestsViewModelTest.kt | 4 ++-- .../recipients/RecipientExporterTest.java | 2 +- .../messaging/jobs/ConfigurationSyncJob.kt | 1 + 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt index 75a3c58752..6e09461054 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt @@ -41,7 +41,7 @@ import org.thoughtcrime.securesms.database.model.SmsMessageRecord import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.util.SearchUtil import org.thoughtcrime.securesms.util.getAccentColor -import java.util.* +import java.util.Locale import kotlin.math.roundToInt class VisibleMessageContentView : ConstraintLayout { @@ -131,7 +131,6 @@ class VisibleMessageContentView : ConstraintLayout { delegate?.scrollToMessageIfPossible(quote.id) } } - val hasMedia = message.slideDeck.asAttachments().isNotEmpty() } if (message is MmsMessageRecord) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 201ea05a11..21ed6bc5e6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -593,6 +593,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { if (oldVersion < lokiV41) { db.execSQL(ConfigDatabase.CREATE_CONFIG_TABLE_COMMAND); + // TODO: delete threads where necessary for one to ones } db.setTransactionSuccessful(); 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 6f021cff42..85d8c8f436 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -144,24 +144,23 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM String groupId = message.getGroupPublicKey(); int duration = message.getDuration(); - Address address = Address.fromSerialized((message.getSyncTarget() != null && !message.getSyncTarget().isEmpty()) ? message.getSyncTarget() : message.getRecipient()); - Recipient recipient = Recipient.from(context, address, false); - if (message.getThreadID() == null || message.getThreadID() < 0) { - StorageProtocol storage = MessagingModuleConfiguration.getShared().getStorage(); - message.setThreadID(storage.getOrCreateThreadIdFor(address)); - } + Address address; try { + if (groupId != null) { + address = Address.fromSerialized(GroupUtil.doubleEncodeGroupID(groupId)); + } else { + address = Address.fromSerialized((message.getSyncTarget() != null && !message.getSyncTarget().isEmpty()) ? message.getSyncTarget() : message.getRecipient()); + } + + Recipient recipient = Recipient.from(context, address, false); + StorageProtocol storage = MessagingModuleConfiguration.getShared().getStorage(); + message.setThreadID(storage.getOrCreateThreadIdFor(address)); + OutgoingExpirationUpdateMessage timerUpdateMessage = new OutgoingExpirationUpdateMessage(recipient, sentTimestamp, duration * 1000L, groupId); mmsDatabase.insertSecureDecryptedMessageOutbox(timerUpdateMessage, message.getThreadID(), sentTimestamp, true); - - if (groupId != null) { - // we need the group ID as recipient for setExpireMessages below - recipient = Recipient.from(context, Address.fromSerialized(GroupUtil.doubleEncodeGroupID(groupId)), false); - } //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/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt b/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt index fdaff22d8f..361c5a4382 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModelTest.kt @@ -5,7 +5,6 @@ import kotlinx.coroutines.flow.first import org.hamcrest.CoreMatchers.endsWith import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat -import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.mockito.Mockito.anyLong @@ -31,7 +30,7 @@ class ConversationViewModelTest: BaseViewModelTest() { private lateinit var recipient: Recipient private val viewModel: ConversationViewModel by lazy { - ConversationViewModel(threadId, edKeyPair, repository, storage) + ConversationViewModel(threadId, edKeyPair, mock(), repository, storage) } @Before diff --git a/app/src/test/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsViewModelTest.kt b/app/src/test/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsViewModelTest.kt index 737c3bec39..8cdb36b6b3 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsViewModelTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsViewModelTest.kt @@ -26,9 +26,9 @@ class MessageRequestsViewModelTest : BaseViewModelTest() { @Test fun `should clear all message requests`() = runBlockingTest { - viewModel.clearAllMessageRequests() + viewModel.clearAllMessageRequests(block = false) - verify(repository).clearAllMessageRequests() + verify(repository).clearAllMessageRequests(block = false) } } \ No newline at end of file diff --git a/app/src/test/java/org/thoughtcrime/securesms/recipients/RecipientExporterTest.java b/app/src/test/java/org/thoughtcrime/securesms/recipients/RecipientExporterTest.java index 5e3467b70c..c20ce39fb1 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/recipients/RecipientExporterTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/recipients/RecipientExporterTest.java @@ -9,7 +9,7 @@ import junit.framework.TestCase; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.session.libsession.utilities.Address; import org.session.libsession.utilities.recipients.Recipient; import org.session.libsession.utilities.recipients.RecipientExporter; diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt index 8ec7727c39..abc89390ca 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt @@ -90,6 +90,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job { Log.d(TAG, "Including delete request for current hashes") } + // TODO: re-add all this to do actual network sync job val batchResponse = SnodeAPI.getSingleTargetSnode(destination.destinationPublicKey()).bind { snode -> SnodeAPI.getRawBatchResponse( snode,