From dd001640a47c8e83f424a7c2e558e93116fb8fa7 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:42:48 +1000 Subject: [PATCH] wip: trying to track down failure to mark conversation as read in delayed group add --- .../org/thoughtcrime/securesms/database/Storage.kt | 10 +++++----- .../securesms/database/ThreadDatabase.java | 4 ++-- .../securesms/notifications/MarkReadReceiver.java | 2 +- .../org/session/libsession/database/StorageProtocol.kt | 2 +- .../libsession/messaging/jobs/BackgroundGroupAddJob.kt | 1 + 5 files changed, 10 insertions(+), 9 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 ca56717a33..0242386cc1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -228,12 +228,12 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co return threadDb.getLastSeenAndHasSent(threadId)?.first() ?: 0L } - override fun markConversationAsRead(threadId: Long, lastSeenTime: Long) { + override fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean) { val threadDb = DatabaseComponent.get(context).threadDatabase() getRecipientForThread(threadId)?.let { recipient -> val currentLastRead = threadDb.getLastSeenAndHasSent(threadId).first() // don't set the last read in the volatile if we didn't set it in the DB - if (!threadDb.markAllAsRead(threadId, recipient.isGroupRecipient, lastSeenTime)) return + if (!threadDb.markAllAsRead(threadId, recipient.isGroupRecipient, lastSeenTime, force) && !force) return // don't process configs for inbox recipients if (recipient.isOpenGroupInboxRecipient) return @@ -500,11 +500,11 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val threadId = when (conversation) { is Conversation.OneToOne -> getThreadIdFor(conversation.sessionId, null, null, createThread = false) is Conversation.LegacyGroup -> getThreadIdFor("", conversation.groupId,null, createThread = false) - is Conversation.Community -> getThreadIdFor("",null, "${conversation.baseCommunityInfo.baseUrl}.${conversation.baseCommunityInfo.room}", createThread = false) + is Conversation.Community -> getThreadIdFor("",null, "${conversation.baseCommunityInfo.baseUrl.removeSuffix("/")}.${conversation.baseCommunityInfo.room}", createThread = false) } if (threadId != null) { if (conversation.lastRead > getLastSeen(threadId)) { - markConversationAsRead(threadId, conversation.lastRead) + markConversationAsRead(threadId, conversation.lastRead, force = true) } updateThread(threadId, false) } @@ -1040,7 +1040,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val volatile = volatileConfig.getOrConstructCommunity(infoServer, infoRoom, pubKey) if (volatile.lastRead != 0L) { val threadId = getThreadId(openGroup) ?: return - markConversationAsRead(threadId, volatile.lastRead) + markConversationAsRead(threadId, volatile.lastRead, force = true) } } 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 3737f52a46..6bbf5861c1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -812,9 +812,9 @@ public class ThreadDatabase extends Database { * @param lastSeenTime * @return true if we have set the last seen for the thread, false if there were no messages in the thread */ - public boolean markAllAsRead(long threadId, boolean isGroupRecipient, long lastSeenTime) { + public boolean markAllAsRead(long threadId, boolean isGroupRecipient, long lastSeenTime, boolean force) { MmsSmsDatabase mmsSmsDatabase = DatabaseComponent.get(context).mmsSmsDatabase(); - if (mmsSmsDatabase.getConversationCount(threadId) <= 0) return false; + if (mmsSmsDatabase.getConversationCount(threadId) <= 0 && !force) return false; List messages = setRead(threadId, lastSeenTime); if (isGroupRecipient) { for (MarkedMessageInfo message: messages) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index f15ce9c11c..309f2732f8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -57,7 +57,7 @@ public class MarkReadReceiver extends BroadcastReceiver { for (long threadId : threadIds) { Log.i(TAG, "Marking as read: " + threadId); StorageProtocol storage = MessagingModuleConfiguration.getShared().getStorage(); - storage.markConversationAsRead(threadId,currentTime); + storage.markConversationAsRead(threadId,currentTime, true); } return null; } 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 8e2a05dc81..4fff833835 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -194,7 +194,7 @@ interface StorageProtocol { * Returns the ID of the `TSIncomingMessage` that was constructed. */ fun persist(message: VisibleMessage, quotes: QuoteModel?, linkPreview: List, groupPublicKey: String?, openGroupID: String?, attachments: List, runThreadUpdate: Boolean): Long? - fun markConversationAsRead(threadId: Long, lastSeenTime: Long) + fun markConversationAsRead(threadId: Long, lastSeenTime: Long, force: Boolean = false) fun getLastSeen(threadId: Long): Long fun updateThread(threadId: Long, unarchive: Boolean) fun insertDataExtractionNotificationMessage(senderPublicKey: String, message: DataExtractionNotificationInfoMessage, sentTimestamp: Long) diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/BackgroundGroupAddJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/BackgroundGroupAddJob.kt index a2111b75df..e717b0d45d 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/BackgroundGroupAddJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/BackgroundGroupAddJob.kt @@ -28,6 +28,7 @@ class BackgroundGroupAddJob(val joinUrl: String): Job { } override suspend fun execute(dispatcherName: String) { + Log.d("Loki-DBG", "adding group $joinUrl") try { val openGroup = OpenGroupUrlParser.parseUrl(joinUrl) val storage = MessagingModuleConfiguration.shared.storage