From e7ea42e28730fd711583d6e72e42f580af5b09cc Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Wed, 5 Mar 2025 15:02:56 +0100 Subject: [PATCH] feat: Keep the logic of master of simply reading message.threads to get the list of impacted threads --- .../mailboxContent/CustomRefreshStrategies.kt | 4 +-- .../cache/mailboxContent/RefreshController.kt | 4 ++- .../cache/mailboxContent/RefreshStrategies.kt | 26 +++++-------------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/CustomRefreshStrategies.kt b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/CustomRefreshStrategies.kt index 73e3120297..8f58db4162 100644 --- a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/CustomRefreshStrategies.kt +++ b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/CustomRefreshStrategies.kt @@ -59,14 +59,12 @@ val snoozeRefreshStrategy = object : DefaultRefreshStrategy { context: Context, mailbox: Mailbox, realm: MutableRealm, - ): Collection { + ) { managedMessage.apply { snoozeState = null snoozeEndDate = null snoozeAction = null } - - return managedMessage.threads } override fun addFolderToImpactedFolders(folderId: String, impactedFolders: ImpactedFolders) { diff --git a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt index 589877b5bd..53b6fb352d 100644 --- a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt +++ b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt @@ -451,7 +451,9 @@ class RefreshController @Inject constructor( scope.ensureActive() val message = currentFolderRefreshStrategy.getMessageFromShortUid(shortUid, folderId, realm = this) ?: return@forEach - threads += currentFolderRefreshStrategy.processDeletedMessage(scope, message, appContext, mailbox, realm = this) + threads += message.threads + + currentFolderRefreshStrategy.processDeletedMessage(scope, message, appContext, mailbox, realm = this) } val impactedFolders = ImpactedFolders() diff --git a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshStrategies.kt b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshStrategies.kt index d057066652..b4924ef486 100644 --- a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshStrategies.kt +++ b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshStrategies.kt @@ -35,20 +35,18 @@ interface RefreshStrategy { fun getMessageFromShortUid(shortUid: String, folderId: String, realm: TypedRealm): Message? - /** - * @return The list of impacted threads that have changed and need to be recomputed. The list of impacted threads will also be - * used to determine what folders need to have their unread count updated. If an extra folder needs its unread count updated - * but no thread has that extra folder as [Thread.folderId], you can define the extra folder you want inside - * [addFolderToImpactedFolders] as they will be inserted inside the list of impacted folders. - */ fun processDeletedMessage( scope: CoroutineScope, managedMessage: Message, context: Context, mailbox: Mailbox, realm: MutableRealm, - ): Collection + ) + /** + * If an extra folder needs its unread count updated but no thread has that extra folder as [Thread.folderId], you can add the + * extra folder inside this method as they will be inserted inside the list of impacted folders. + */ fun addFolderToImpactedFolders(folderId: String, impactedFolders: ImpactedFolders) fun processDeletedThread(thread: Thread, realm: MutableRealm) fun shouldQueryFolderThreadsOnDeletedUid(): Boolean @@ -81,19 +79,7 @@ interface DefaultRefreshStrategy : RefreshStrategy { context: Context, mailbox: Mailbox, realm: MutableRealm, - ): Collection = buildSet { - /** - * This list is reversed because we'll delete items while looping over it. - * Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item. - * Looping in reverse enables us to not skip any item. - */ - managedMessage.threads.asReversed().forEach { thread -> - scope.ensureActive() - - val isSuccess = thread.messages.remove(managedMessage) - if (isSuccess) add(thread) - } - + ) { MessageController.deleteMessage(context, mailbox, managedMessage, realm) }