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 SentryLog when mailboxId uses the default value for configuration #1986

Merged
Merged
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
25 changes: 17 additions & 8 deletions app/src/main/java/com/infomaniak/mail/data/cache/RealmDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.infomaniak.mail.data.cache

import android.content.Context
import com.infomaniak.mail.data.models.AppSettings
import com.infomaniak.mail.data.models.AppSettings.Companion.DEFAULT_ID
import com.infomaniak.mail.data.models.Attachment
import com.infomaniak.mail.data.models.Bimi
import com.infomaniak.mail.data.models.Folder
Expand All @@ -44,6 +45,8 @@ import com.infomaniak.mail.utils.LocalStorageUtils
import io.realm.kotlin.Realm
import io.realm.kotlin.RealmConfiguration
import io.realm.kotlin.internal.platform.WeakReference
import io.sentry.Sentry
import io.sentry.SentryLevel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
Expand Down Expand Up @@ -86,7 +89,7 @@ object RealmDatabase {
val mailboxInfo get() = Realm.open(RealmConfig.mailboxInfo)

val newMailboxContentInstance get() = newMailboxContentInstance(AccountUtils.currentUserId, AccountUtils.currentMailboxId)
fun newMailboxContentInstance(userId: Int, mailboxId: Int) = Realm.open(RealmConfig.mailboxContent(mailboxId, userId))
fun newMailboxContentInstance(userId: Int, mailboxId: Int) = Realm.open(RealmConfig.mailboxContent(userId, mailboxId))

class MailboxContent {
operator fun invoke() = runBlocking(Dispatchers.IO) {
Expand Down Expand Up @@ -139,7 +142,7 @@ object RealmDatabase {

//region Delete Realm
fun deleteMailboxContent(mailboxId: Int, userId: Int = AccountUtils.currentUserId) {
Realm.deleteRealm(RealmConfig.mailboxContent(mailboxId, userId))
Realm.deleteRealm(RealmConfig.mailboxContent(userId, mailboxId))
}

fun removeUserData(context: Context, userId: Int) {
Expand Down Expand Up @@ -229,12 +232,18 @@ object RealmDatabase {
.migration(MAILBOX_INFO_MIGRATION)
.build()

fun mailboxContent(mailboxId: Int, userId: Int) = RealmConfiguration
.Builder(mailboxContentSet)
.name(mailboxContentDbName(userId, mailboxId))
.schemaVersion(MAILBOX_CONTENT_SCHEMA_VERSION)
.migration(MAILBOX_CONTENT_MIGRATION)
.build()
fun mailboxContent(userId: Int, mailboxId: Int): RealmConfiguration {

if (mailboxId == DEFAULT_ID) {
Sentry.captureMessage("RealmConfiguration problem with mailbox content, default ID is used.", SentryLevel.ERROR)
}

return RealmConfiguration.Builder(mailboxContentSet)
.name(mailboxContentDbName(userId, mailboxId))
.schemaVersion(MAILBOX_CONTENT_SCHEMA_VERSION)
.migration(MAILBOX_CONTENT_MIGRATION)
.build()
}
//endregion
}
}
Loading