Skip to content

Commit

Permalink
Merge pull request #1927 from Infomaniak/delete-draft-orphans
Browse files Browse the repository at this point in the history
Delete Drafts orphans after sending the Sentry about them
  • Loading branch information
KevinBoulongne committed Jun 20, 2024
2 parents 80bbfaf + e19f398 commit 98381a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.infomaniak.mail.utils
import android.os.Bundle
import androidx.navigation.NavController
import com.infomaniak.mail.BuildConfig
import com.infomaniak.mail.data.cache.mailboxContent.DraftController
import com.infomaniak.mail.data.cache.mailboxContent.MessageController
import com.infomaniak.mail.data.cache.mailboxContent.ThreadController
import com.infomaniak.mail.data.models.Folder
Expand Down Expand Up @@ -242,13 +241,12 @@ object SentryDebug {
return orphanThreads
}

fun sendOrphanDrafts(realm: TypedRealm) {
val orphanDrafts = DraftController.getOrphanDrafts(realm)
if (orphanDrafts.isNotEmpty()) {
fun sendOrphanDrafts(orphans: List<Draft>) {
if (orphans.isNotEmpty()) {
Sentry.withScope { scope ->
scope.setExtra(
"orphanDrafts",
orphanDrafts.joinToString {
orphans.joinToString {
if (it.messageUid == null) {
"${Draft::localUuid.name}: [${it.localUuid}]"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ class DraftsActionsWorker @AssistedInject constructor(

mailboxContentRealm.executeRealmCallbacks(realmActionsOnDraft)

SentryDebug.sendOrphanDrafts(mailboxContentRealm)
mailboxContentRealm.writeBlocking {
val orphans = DraftController.getOrphanDrafts(realm = this)
SentryDebug.sendOrphanDrafts(orphans)
delete(orphans)
}

showDraftErrorNotification(isTrackedDraftSuccess, trackedDraftErrorMessageResId, trackedDraftAction)

Expand Down

0 comments on commit 98381a9

Please sign in to comment.