@@ -19,6 +19,7 @@ package com.infomaniak.mail.data.cache
19
19
20
20
import android.content.Context
21
21
import com.infomaniak.mail.data.models.AppSettings
22
+ import com.infomaniak.mail.data.models.AppSettings.Companion.DEFAULT_ID
22
23
import com.infomaniak.mail.data.models.Attachment
23
24
import com.infomaniak.mail.data.models.Bimi
24
25
import com.infomaniak.mail.data.models.Folder
@@ -44,6 +45,8 @@ import com.infomaniak.mail.utils.LocalStorageUtils
44
45
import io.realm.kotlin.Realm
45
46
import io.realm.kotlin.RealmConfiguration
46
47
import io.realm.kotlin.internal.platform.WeakReference
48
+ import io.sentry.Sentry
49
+ import io.sentry.SentryLevel
47
50
import kotlinx.coroutines.Dispatchers
48
51
import kotlinx.coroutines.runBlocking
49
52
import kotlinx.coroutines.sync.Mutex
@@ -86,7 +89,7 @@ object RealmDatabase {
86
89
val mailboxInfo get() = Realm .open(RealmConfig .mailboxInfo)
87
90
88
91
val newMailboxContentInstance get() = newMailboxContentInstance(AccountUtils .currentUserId, AccountUtils .currentMailboxId)
89
- fun newMailboxContentInstance (userId : Int , mailboxId : Int ) = Realm .open(RealmConfig .mailboxContent(mailboxId, userId ))
92
+ fun newMailboxContentInstance (userId : Int , mailboxId : Int ) = Realm .open(RealmConfig .mailboxContent(userId, mailboxId ))
90
93
91
94
class MailboxContent {
92
95
operator fun invoke () = runBlocking(Dispatchers .IO ) {
@@ -139,7 +142,7 @@ object RealmDatabase {
139
142
140
143
// region Delete Realm
141
144
fun deleteMailboxContent (mailboxId : Int , userId : Int = AccountUtils .currentUserId) {
142
- Realm .deleteRealm(RealmConfig .mailboxContent(mailboxId, userId ))
145
+ Realm .deleteRealm(RealmConfig .mailboxContent(userId, mailboxId ))
143
146
}
144
147
145
148
fun removeUserData (context : Context , userId : Int ) {
@@ -229,12 +232,18 @@ object RealmDatabase {
229
232
.migration(MAILBOX_INFO_MIGRATION )
230
233
.build()
231
234
232
- fun mailboxContent (mailboxId : Int , userId : Int ) = RealmConfiguration
233
- .Builder (mailboxContentSet)
234
- .name(mailboxContentDbName(userId, mailboxId))
235
- .schemaVersion(MAILBOX_CONTENT_SCHEMA_VERSION )
236
- .migration(MAILBOX_CONTENT_MIGRATION )
237
- .build()
235
+ fun mailboxContent (userId : Int , mailboxId : Int ): RealmConfiguration {
236
+
237
+ if (mailboxId == DEFAULT_ID ) {
238
+ Sentry .captureMessage(" RealmConfiguration problem with mailbox content, default ID is used." , SentryLevel .ERROR )
239
+ }
240
+
241
+ return RealmConfiguration .Builder (mailboxContentSet)
242
+ .name(mailboxContentDbName(userId, mailboxId))
243
+ .schemaVersion(MAILBOX_CONTENT_SCHEMA_VERSION )
244
+ .migration(MAILBOX_CONTENT_MIGRATION )
245
+ .build()
246
+ }
238
247
// endregion
239
248
}
240
249
}
0 commit comments