From 2c52039c2e983aba6a0c58a53809c18e0180360e Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Wed, 19 Jun 2024 11:39:09 +0200 Subject: [PATCH] Delete Drafts orphans after sending the Sentry about them --- .../mail/data/cache/mailboxContent/ThreadController.kt | 4 ++-- app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt | 3 ++- .../java/com/infomaniak/mail/workers/DraftsActionsWorker.kt | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/ThreadController.kt b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/ThreadController.kt index 66c2686f573..60f8564385c 100644 --- a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/ThreadController.kt +++ b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/ThreadController.kt @@ -75,8 +75,8 @@ class ThreadController @Inject constructor( /** * Initialize and retrieve the search Threads obtained from the API. - * - Format the remote threads to make them compatible with the existing logic. - * - Preserve old message data if it already exists locally. + * - Format the remote Threads to make them compatible with the existing logic. + * - Preserve old Messages data if it already exists locally. * - Handle duplicates using the existing logic. * @param remoteThreads The list of API Threads that need to be processed. * @param filterFolder The selected Folder on which we filter the Search. diff --git a/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt b/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt index f27c7fb7ef0..bb1f7e651b6 100644 --- a/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt +++ b/app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt @@ -242,7 +242,7 @@ object SentryDebug { return orphanThreads } - fun sendOrphanDrafts(realm: TypedRealm) { + fun sendOrphanDrafts(realm: TypedRealm): RealmResults { val orphanDrafts = DraftController.getOrphanDrafts(realm) if (orphanDrafts.isNotEmpty()) { Sentry.withScope { scope -> @@ -259,6 +259,7 @@ object SentryDebug { Sentry.captureMessage("We found some orphan Drafts.", SentryLevel.ERROR) } } + return orphanDrafts } fun sendOverScrolledMessage(clientWidth: Int, scrollWidth: Int, messageUid: String) { diff --git a/app/src/main/java/com/infomaniak/mail/workers/DraftsActionsWorker.kt b/app/src/main/java/com/infomaniak/mail/workers/DraftsActionsWorker.kt index df0dc35f01f..727dd6bdcb7 100644 --- a/app/src/main/java/com/infomaniak/mail/workers/DraftsActionsWorker.kt +++ b/app/src/main/java/com/infomaniak/mail/workers/DraftsActionsWorker.kt @@ -197,7 +197,10 @@ class DraftsActionsWorker @AssistedInject constructor( mailboxContentRealm.executeRealmCallbacks(realmActionsOnDraft) - SentryDebug.sendOrphanDrafts(mailboxContentRealm) + mailboxContentRealm.writeBlocking { + val orphans = SentryDebug.sendOrphanDrafts(realm = this) + delete(orphans) + } showDraftErrorNotification(isTrackedDraftSuccess, trackedDraftErrorMessageResId, trackedDraftAction)