From f7b4fe216f4ec7509cfab109ee4eadaec1261e2a Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Tue, 2 May 2023 16:30:35 +1000 Subject: [PATCH] fix: removing debug logs, adding failure error handling logs for expiry message updater, properly using the message thread ID created for the expiring messages. Process the non-thread messages properly with await in BatchMessageReceiveJob --- .../main/java/org/thoughtcrime/securesms/database/Storage.kt | 3 --- .../org/thoughtcrime/securesms/database/ThreadDatabase.java | 2 -- .../securesms/service/ExpiringMessageManager.java | 4 ++-- .../securesms/util/ConfigurationMessageUtilities.kt | 4 +--- .../libsession/messaging/jobs/BatchMessageReceiveJob.kt | 5 +---- 5 files changed, 4 insertions(+), 14 deletions(-) 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 cb487ef973..c5f2609e5f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -96,7 +96,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co // TODO: maybe add time here from formation / creation message override fun threadCreated(address: Address, threadId: Long) { if (!getRecipientApproved(address)) return // don't store unapproved / message requests - Log.d("Loki-DBG", "creating thread for $address\nExecution context:\n${Thread.currentThread().stackTrace.joinToString("\n")}") val volatile = configFactory.convoVolatile ?: return if (address.isGroup) { @@ -135,7 +134,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co } override fun threadDeleted(address: Address, threadId: Long) { - Log.d("Loki-DBG", "deleting thread for $address\nExecution context:\n${Thread.currentThread().stackTrace.joinToString("\n")}") val volatile = configFactory.convoVolatile ?: return if (address.isGroup) { @@ -1100,7 +1098,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co setPinned(conversationThreadId, contact.priority == ConfigBase.PRIORITY_PINNED) } } - Log.d("Loki-DBG", "Updated contact $contact") } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index 4afdff3c7c..399d33f9ea 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -315,7 +315,6 @@ public class ThreadDatabase extends Database { ContentValues contentValues = new ContentValues(1); contentValues.put(READ, 1); - Log.d("Loki-DBG", "setRead "+threadId+" @ "+lastReadTime); contentValues.put(LAST_SEEN, lastReadTime); SQLiteDatabase db = databaseHelper.getWritableDatabase(); @@ -336,7 +335,6 @@ public class ThreadDatabase extends Database { contentValues.put(UNREAD_MENTION_COUNT, 0); if (lastSeen) { - Log.d("Loki-DBG", "setRead "+threadId+" @ current time"); contentValues.put(LAST_SEEN, SnodeAPI.getNowWithOffset()); } 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 d671de96cb..6f021cff42 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -153,7 +153,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM try { OutgoingExpirationUpdateMessage timerUpdateMessage = new OutgoingExpirationUpdateMessage(recipient, sentTimestamp, duration * 1000L, groupId); - mmsDatabase.insertSecureDecryptedMessageOutbox(timerUpdateMessage, -1, sentTimestamp, true); + mmsDatabase.insertSecureDecryptedMessageOutbox(timerUpdateMessage, message.getThreadID(), sentTimestamp, true); if (groupId != null) { // we need the group ID as recipient for setExpireMessages below @@ -163,7 +163,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM MessagingModuleConfiguration.getShared().getStorage().setExpirationTimer(recipient.getAddress().serialize(), duration); } catch (MmsException | IOException ioe) { - Log.e("Loki", "Failed to insert expiration update message."); + Log.e("Loki", "Failed to insert expiration update message.", ioe); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt index 8f4fd61044..5fa018b4da 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt @@ -31,7 +31,7 @@ import java.util.Timer object ConfigurationMessageUtilities { - val debouncer = WindowDebouncer(3000, Timer()) + private val debouncer = WindowDebouncer(3000, Timer()) private fun scheduleConfigSync(userPublicKey: String) { debouncer.publish { @@ -41,11 +41,9 @@ object ConfigurationMessageUtilities { val currentStorageJob = storage.getConfigSyncJob(ourDestination) if (currentStorageJob != null) { (currentStorageJob as ConfigurationSyncJob).shouldRunAgain.set(true) - Log.d("Loki-DBG", "Not scheduling another one") return@publish } val newConfigSync = ConfigurationSyncJob(ourDestination) - Log.d("Loki", "Scheduling new ConfigurationSyncJob") JobQueue.shared.add(newConfigSync) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt index b5e7cf8848..5d4e0f8547 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/BatchMessageReceiveJob.kt @@ -156,7 +156,6 @@ class BatchMessageReceiveJob( val messageIds = linkedMapOf>() val myLastSeen = storage.getLastSeen(threadId) var newLastSeen = if (myLastSeen == -1L) 0 else myLastSeen - Log.d("Loki-DBG", "myLastSeen = $newLastSeen") messages.forEach { (parameters, message, proto) -> try { when (message) { @@ -226,11 +225,9 @@ class BatchMessageReceiveJob( // last seen will be the current last seen if not changed (re-computes the read counts for thread record) // might have been updated from a different thread at this point val currentLastSeen = storage.getLastSeen(threadId).let { if (it == -1L) 0 else it } - Log.d("Loki-DBG", "currentLastSeen = $currentLastSeen") if (currentLastSeen > newLastSeen) { newLastSeen = currentLastSeen } - Log.d("Loki-DBG", "newLastSeen = $newLastSeen") storage.markConversationAsRead(threadId, newLastSeen) storage.updateThread(threadId, true) SSKEnvironment.shared.notificationManager.updateNotification(context, threadId) @@ -243,7 +240,7 @@ class BatchMessageReceiveJob( } // await all thread processing deferredThreadMap.awaitAll() - processMessages(NO_THREAD_MAPPING, noThreadMessages) + processMessages(NO_THREAD_MAPPING, noThreadMessages).await() } if (failures.isEmpty()) { handleSuccess(dispatcherName)