Skip to content

Commit

Permalink
feat: Compute snooze state in thread (#2218)
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX authored Mar 7, 2025
2 parents 410845e + fd038fc commit f48fa20
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ object RealmDatabase {
//region Configurations versions
const val USER_INFO_SCHEMA_VERSION = 2L
const val MAILBOX_INFO_SCHEMA_VERSION = 8L
const val MAILBOX_CONTENT_SCHEMA_VERSION = 21L
const val MAILBOX_CONTENT_SCHEMA_VERSION = 22L
//endregion

//region Configurations names
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/com/infomaniak/mail/data/models/SnoozeState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Infomaniak Mail - Android
* Copyright (C) 2025 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.mail.data.models

import com.infomaniak.core.utils.ApiEnum

enum class SnoozeState(override val apiValue: String) : ApiEnum {
Snoozed(apiValue = "snoozed"), // Has been snoozed and the snooze end time has not been reached yet
Unsnoozed(apiValue = "unsnoozed"), // Used to be snoozed but the snooze end time has been reached and the message came back
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

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

import com.infomaniak.core.utils.ApiEnum
import com.infomaniak.core.utils.apiEnum
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.SnoozeState
import com.infomaniak.mail.data.models.SwissTransferFile
import com.infomaniak.mail.data.models.calendar.CalendarEventResponse
import com.infomaniak.mail.data.models.correspondent.Recipient
Expand Down Expand Up @@ -167,9 +167,10 @@ class Message : RealmObject {
@Transient
@Ignore
var shouldHideDivider: Boolean = false
//endregion

@Ignore
var snoozeState: SnoozeState? by apiEnum(::_snoozeState)
//endregion

val threads by backlinks(Thread::messages)

Expand Down Expand Up @@ -230,12 +231,6 @@ class Message : RealmObject {
ACKNOWLEDGED,
}

enum class SnoozeState(override val apiValue: String) : ApiEnum {
Snoozed(apiValue = "snoozed"),
Unsnoozed(apiValue = "unsnoozed"),
WasSnoozed(apiValue = "was_snoozed"),
}

fun initLocalValues(
messageInitialState: MessageInitialState,
latestCalendarEventResponse: CalendarEventResponse?,
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/infomaniak/mail/data/models/thread/Thread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

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

import com.infomaniak.core.utils.apiEnum
import com.infomaniak.mail.MatomoMail.SEARCH_FOLDER_FILTER_NAME
import com.infomaniak.mail.data.api.RealmInstantSerializer
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
import com.infomaniak.mail.data.models.Bimi
import com.infomaniak.mail.data.models.Folder
import com.infomaniak.mail.data.models.Folder.FolderRole
import com.infomaniak.mail.data.models.SnoozeState
import com.infomaniak.mail.data.models.correspondent.Recipient
import com.infomaniak.mail.data.models.message.Message
import com.infomaniak.mail.utils.AccountUtils
Expand All @@ -38,6 +40,7 @@ import io.realm.kotlin.serializers.RealmListKSerializer
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.Ignore
import io.realm.kotlin.types.annotations.PrimaryKey
import io.sentry.Sentry
import io.sentry.SentryLevel
Expand Down Expand Up @@ -90,8 +93,18 @@ class Thread : RealmObject {
var isLocallyMovedOut: Boolean = false
@Transient
var numberOfScheduledDrafts: Int = 0
@Transient
private var _snoozeState: String? = null
@Transient
var snoozeEndDate: RealmInstant? = null
@Transient
var snoozeAction: String? = null
//endregion

@Ignore
var snoozeState: SnoozeState? by apiEnum(::_snoozeState)
private set

private val _folders by backlinks(Folder::threads)
val folder
get() = runCatching {
Expand Down Expand Up @@ -185,10 +198,21 @@ class Thread : RealmObject {
isForwarded = false
hasAttachable = false
numberOfScheduledDrafts = 0
snoozeState = null
snoozeEndDate = null
snoozeAction = null
}

private fun updateThread() {

fun Thread.updateSnoozeStatesBasedOn(message: Message) {
message.snoozeState?.let {
snoozeState = it
snoozeEndDate = message.snoozeEndDate
snoozeAction = message.snoozeAction
}
}

messages.sortBy { it.date }

messages.forEach { message ->
Expand All @@ -208,8 +232,12 @@ class Thread : RealmObject {
}
if (message.hasAttachable) hasAttachable = true
if (message.isScheduledDraft) numberOfScheduledDrafts++

updateSnoozeStatesBasedOn(message)
}

duplicates.forEach(::updateSnoozeStatesBasedOn)

date = messages.last { it.folderId == folderId }.date
subject = messages.first().subject
}
Expand Down

0 comments on commit f48fa20

Please sign in to comment.