Skip to content

Commit dec7380

Browse files
LunarXKevinBoulongne
authored andcommitted
feat: Compute thread snooze state at Thread level
1 parent a1c6b84 commit dec7380

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

app/src/main/java/com/infomaniak/mail/data/cache/RealmDatabase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ object RealmDatabase {
161161
//region Configurations versions
162162
const val USER_INFO_SCHEMA_VERSION = 2L
163163
const val MAILBOX_INFO_SCHEMA_VERSION = 8L
164-
const val MAILBOX_CONTENT_SCHEMA_VERSION = 21L
164+
const val MAILBOX_CONTENT_SCHEMA_VERSION = 22L
165165
//endregion
166166

167167
//region Configurations names
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Infomaniak Mail - Android
3+
* Copyright (C) 2025 Infomaniak Network SA
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.infomaniak.mail.data.models
19+
20+
import com.infomaniak.core.utils.ApiEnum
21+
22+
enum class SnoozeState(override val apiValue: String) : ApiEnum {
23+
Snoozed(apiValue = "snoozed"),
24+
Unsnoozed(apiValue = "unsnoozed"),
25+
WasSnoozed(apiValue = "was_snoozed"),
26+
}

app/src/main/java/com/infomaniak/mail/data/models/message/Message.kt

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
package com.infomaniak.mail.data.models.message
2121

22-
import com.infomaniak.core.utils.ApiEnum
2322
import com.infomaniak.core.utils.apiEnum
2423
import com.infomaniak.lib.core.utils.Utils.enumValueOfOrNull
2524
import com.infomaniak.mail.data.api.RealmInstantSerializer
2625
import com.infomaniak.mail.data.api.UnwrappingJsonListSerializer
2726
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
2827
import com.infomaniak.mail.data.models.Attachment
2928
import com.infomaniak.mail.data.models.Bimi
29+
import com.infomaniak.mail.data.models.SnoozeState
3030
import com.infomaniak.mail.data.models.SwissTransferFile
3131
import com.infomaniak.mail.data.models.calendar.CalendarEventResponse
3232
import com.infomaniak.mail.data.models.correspondent.Recipient
@@ -230,12 +230,6 @@ class Message : RealmObject {
230230
ACKNOWLEDGED,
231231
}
232232

233-
enum class SnoozeState(override val apiValue: String) : ApiEnum {
234-
Snoozed(apiValue = "snoozed"),
235-
Unsnoozed(apiValue = "unsnoozed"),
236-
WasSnoozed(apiValue = "was_snoozed"),
237-
}
238-
239233
fun initLocalValues(
240234
messageInitialState: MessageInitialState,
241235
latestCalendarEventResponse: CalendarEventResponse?,

app/src/main/java/com/infomaniak/mail/data/models/thread/Thread.kt

+19
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
package com.infomaniak.mail.data.models.thread
2121

22+
import com.infomaniak.core.utils.apiEnumValueOfOrNull
2223
import com.infomaniak.mail.MatomoMail.SEARCH_FOLDER_FILTER_NAME
2324
import com.infomaniak.mail.data.api.RealmInstantSerializer
2425
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
2526
import com.infomaniak.mail.data.models.Bimi
2627
import com.infomaniak.mail.data.models.Folder
2728
import com.infomaniak.mail.data.models.Folder.FolderRole
29+
import com.infomaniak.mail.data.models.SnoozeState
2830
import com.infomaniak.mail.data.models.correspondent.Recipient
2931
import com.infomaniak.mail.data.models.message.Message
3032
import com.infomaniak.mail.utils.AccountUtils
@@ -90,6 +92,12 @@ class Thread : RealmObject {
9092
var isLocallyMovedOut: Boolean = false
9193
@Transient
9294
var numberOfScheduledDrafts: Int = 0
95+
@Transient
96+
private var _snoozeState: String? = null
97+
@Transient
98+
var snoozeEndDate: RealmInstant? = null
99+
@Transient
100+
var snoozeAction: String? = null
93101
//endregion
94102

95103
private val _folders by backlinks(Folder::threads)
@@ -126,6 +134,8 @@ class Thread : RealmObject {
126134

127135
val isOnlyOneDraft get() = messages.count() == 1 && hasDrafts
128136

137+
val snoozeState get() = apiEnumValueOfOrNull<SnoozeState>(_snoozeState)
138+
129139
fun addMessageWithConditions(newMessage: Message, realm: TypedRealm) {
130140

131141
val shouldAddMessage = when (FolderController.getFolder(folderId, realm)?.role) {
@@ -185,6 +195,9 @@ class Thread : RealmObject {
185195
isForwarded = false
186196
hasAttachable = false
187197
numberOfScheduledDrafts = 0
198+
_snoozeState = null
199+
snoozeEndDate = null
200+
snoozeAction = null
188201
}
189202

190203
private fun updateThread() {
@@ -208,6 +221,12 @@ class Thread : RealmObject {
208221
}
209222
if (message.hasAttachable) hasAttachable = true
210223
if (message.isScheduledDraft) numberOfScheduledDrafts++
224+
225+
message.snoozeState?.let {
226+
_snoozeState = it.apiValue
227+
snoozeEndDate = message.snoozeEndDate
228+
snoozeAction = message.snoozeAction
229+
}
211230
}
212231

213232
date = messages.last { it.folderId == folderId }.date

0 commit comments

Comments
 (0)