Skip to content

Commit

Permalink
Merge pull request #2092 from Infomaniak/update-sentry-condition
Browse files Browse the repository at this point in the history
fix: Add missing Search folder check in a Sentry
  • Loading branch information
KevinBoulongne authored Nov 6, 2024
2 parents 7766fb5 + 8e02310 commit 1b2e981
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.infomaniak.mail.data.models.message
import com.infomaniak.lib.core.utils.Utils.enumValueOfOrNull
import com.infomaniak.mail.data.api.RealmInstantSerializer
import com.infomaniak.mail.data.api.UnwrappingJsonListSerializer
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
import com.infomaniak.mail.data.models.Attachment
import com.infomaniak.mail.data.models.Bimi
import com.infomaniak.mail.data.models.SwissTransferFile
Expand Down Expand Up @@ -157,13 +158,11 @@ class Message : RealmObject {

private val threadsDuplicatedIn by backlinks(Thread::duplicates)

// TODO: When there is no more issue with the `_folders` backlink in the Thread model,
// we will be able to replace this `first { … }` with `first()`.
// TODO: Remove this `runCatching / getOrElse` when the issue is fixed
inline val folder
get() = runCatching {
threads.single { it.folder.id == folderId }.folder
threads.single { it.folder.id == folderId || it.folder.id == FolderController.SEARCH_FOLDER_ID }.folder
}.getOrElse { exception ->
// TODO: I think this Sentry can't happen, but better safe than sorry. Weird possibilities are endless.

val reason = when {
threads.isEmpty() -> "no parent Threads" // Message has 0 parent threads
Expand All @@ -185,7 +184,7 @@ class Message : RealmObject {
scope.setExtra("exception", exception.message.toString())
}

threads.first().folder
return@getOrElse (threads.firstOrNull { it.folder.id == folderId } ?: threads.first()).folder
}

inline val sender get() = from.firstOrNull()
Expand Down

0 comments on commit 1b2e981

Please sign in to comment.