Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more info about supposed empty Thread in Sentry #2030

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class ThreadController @Inject constructor(
// It's possibly because we are out of sync, and the situation will resolve by itself shortly?
if (emptyThreads.isNotEmpty()) {
emptyThreads.forEach {
SentryDebug.sendEmptyThread(it, "No Message in a Thread when refreshing a Folder")
SentryDebug.sendEmptyThread(it, "No Message in a Thread when refreshing a Folder", realm = this)
}
delete(emptyThreadsQuery)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.infomaniak.mail.R
import com.infomaniak.mail.data.LocalSettings
import com.infomaniak.mail.data.LocalSettings.SwipeAction
import com.infomaniak.mail.data.LocalSettings.ThreadDensity
import com.infomaniak.mail.data.cache.RealmDatabase
import com.infomaniak.mail.data.models.Folder.FolderRole
import com.infomaniak.mail.data.models.correspondent.Recipient
import com.infomaniak.mail.data.models.thread.Thread
Expand All @@ -74,6 +75,7 @@ import com.infomaniak.lib.core.R as RCore
class ThreadListAdapter @Inject constructor(
@ActivityContext context: Context,
private val localSettings: LocalSettings,
private val mailboxContentRealm: RealmDatabase.MailboxContent,
) : DragDropSwipeAdapter<Any, ThreadListViewHolder>(mutableListOf()), RealmChangesBinding.OnRealmChanged<Thread> {

private var formatListJob: Job? = null
Expand Down Expand Up @@ -199,7 +201,11 @@ class ThreadListAdapter @Inject constructor(
// TODO: Find why we are sometimes displaying empty Threads, and fix it instead of just deleting them.
// It's possibly because we are out of sync, and the situation will resolve by itself shortly?
callbacks?.deleteThreadInRealm?.invoke(thread.uid)
SentryDebug.sendEmptyThread(thread, "No Message in the Thread when displaying it in ThreadList")
SentryDebug.sendEmptyThread(
thread = thread,
message = "No Message in the Thread when displaying it in ThreadList",
realm = mailboxContentRealm(),
)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class ThreadViewModel @Inject constructor(
appContext.trackUserInfo("nbMessagesInThread", nbMessages)

when (nbMessages) {
0 -> SentryDebug.sendEmptyThread(thread, "No Message in the Thread when opening it")
0 -> SentryDebug.sendEmptyThread(thread, "No Message in the Thread when opening it", mailboxContentRealm())
1 -> appContext.trackUserInfo("oneMessagesInThread")
else -> appContext.trackUserInfo("multipleMessagesInThread", nbMessages)
}
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,24 @@ object SentryDebug {
// If this doesn't trigger after a certain amount of time, you can remove it.
//
// Also added in ThreadListAdapter & ThreadController the 04/06/24.
fun sendEmptyThread(thread: Thread, message: String) = with(thread) {
fun sendEmptyThread(thread: Thread, message: String, realm: TypedRealm) = with(thread) {

val messageFromThreadUid = MessageController.getMessage(uid, realm)

Sentry.captureMessage(message, SentryLevel.ERROR) { scope ->
scope.setExtra("currentUserId", "${AccountUtils.currentUserId}")
scope.setExtra("currentMailboxEmail", AccountUtils.currentMailboxEmail.toString())
scope.setExtra("folderId", folderId)
scope.setExtra("folder.id", folder.id)
scope.setExtra("folder.role", folder.role?.name.toString())
scope.setExtra("uid", uid)
scope.setExtra("messages.count", "${messages.count()}")
scope.setExtra("duplicates.count", "${duplicates.count()}")
scope.setExtra("isFromSearch", "$isFromSearch")
scope.setExtra("hasDrafts", "$hasDrafts")
scope.setExtra("01. currentUserId", "${AccountUtils.currentUserId}")
scope.setExtra("02. currentMailboxEmail", AccountUtils.currentMailboxEmail.toString())
scope.setExtra("03. folderId", folderId)
scope.setExtra("04. folder.id", folder.id)
scope.setExtra("05. folder.role", folder.role?.name.toString())
scope.setExtra("06. thread.uid", uid)
scope.setExtra("07. thread.messages.count", "${messages.count()}")
scope.setExtra("08. thread.duplicates.count", "${duplicates.count()}")
scope.setExtra("09. thread.isFromSearch", "$isFromSearch")
scope.setExtra("10. thread.hasDrafts", "$hasDrafts")
scope.setExtra("11. message.uid", "${messageFromThreadUid?.uid}")
scope.setExtra("12. message.folderId", "${messageFromThreadUid?.folderId}")
scope.setExtra("13. message.folder.id", "${messageFromThreadUid?.folder?.id}")
}
}

Expand Down
Loading