-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Extract each RefreshStrategy to its own file
- Loading branch information
1 parent
612359e
commit 106bce9
Showing
7 changed files
with
146 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...a/com/infomaniak/mail/data/cache/mailboxContent/refreshStrategies/InboxRefreshStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.cache.mailboxContent.refreshStrategies | ||
|
||
import com.infomaniak.mail.data.cache.mailboxContent.ImpactedFolders | ||
import com.infomaniak.mail.data.cache.mailboxContent.ThreadController | ||
import com.infomaniak.mail.data.models.Folder | ||
import com.infomaniak.mail.data.models.thread.Thread | ||
import io.realm.kotlin.TypedRealm | ||
|
||
val inboxRefreshStrategy = object : DefaultRefreshStrategy { | ||
override fun queryFolderThreads(folderId: String, realm: TypedRealm): List<Thread> { | ||
return ThreadController.getInboxThreadsWithSnoozeFilter(withSnooze = false, realm = realm) | ||
} | ||
|
||
override fun otherFolderRolesToQueryThreads(): List<Folder.FolderRole> = listOf(Folder.FolderRole.SNOOZED) | ||
|
||
override fun addFolderToImpactedFolders(folderId: String, impactedFolders: ImpactedFolders) { | ||
impactedFolders += folderId | ||
impactedFolders += Folder.FolderRole.SNOOZED | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...n/java/com/infomaniak/mail/data/cache/mailboxContent/refreshStrategies/RefreshStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.cache.mailboxContent.refreshStrategies | ||
|
||
import android.content.Context | ||
import com.infomaniak.mail.data.cache.mailboxContent.ImpactedFolders | ||
import com.infomaniak.mail.data.models.Folder | ||
import com.infomaniak.mail.data.models.mailbox.Mailbox | ||
import com.infomaniak.mail.data.models.message.Message | ||
import com.infomaniak.mail.data.models.thread.Thread | ||
import io.realm.kotlin.MutableRealm | ||
import io.realm.kotlin.TypedRealm | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
interface RefreshStrategy { | ||
fun queryFolderThreads(folderId: String, realm: TypedRealm): List<Thread> | ||
|
||
fun otherFolderRolesToQueryThreads(): List<Folder.FolderRole> | ||
|
||
fun shouldHideEmptyFolder(): Boolean | ||
|
||
fun getMessageFromShortUid(shortUid: String, folderId: String, realm: TypedRealm): Message? | ||
|
||
fun processDeletedMessage( | ||
scope: CoroutineScope, | ||
managedMessage: Message, | ||
context: Context, | ||
mailbox: Mailbox, | ||
realm: MutableRealm, | ||
) | ||
|
||
/** | ||
* If an extra folder needs its unread count updated but no thread has that extra folder as [Thread.folderId], you can add the | ||
* extra folder inside this method as they will be inserted inside the list of impacted folders. | ||
*/ | ||
fun addFolderToImpactedFolders(folderId: String, impactedFolders: ImpactedFolders) | ||
|
||
fun processDeletedThread(thread: Thread, realm: MutableRealm) | ||
|
||
fun shouldQueryFolderThreadsOnDeletedUid(): Boolean | ||
|
||
/** | ||
* About the [impactedThreadsManaged]: | ||
* This set will be updated throughout the whole process of handling added Messages. | ||
* It represents all the Threads that will need to be recomputed to reflect the changes of the newly added Messages. | ||
* We need to pass down a reference to the MutableSet to enable both addition and removal of Threads in it. | ||
*/ | ||
fun handleAddedMessages( | ||
scope: CoroutineScope, | ||
remoteMessage: Message, | ||
isConversationMode: Boolean, | ||
impactedThreadsManaged: MutableSet<Thread>, | ||
realm: MutableRealm, | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
...omaniak/mail/data/cache/mailboxContent/refreshStrategies/ScheduledDraftRefreshStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.cache.mailboxContent.refreshStrategies | ||
|
||
val scheduledDraftRefreshStrategy = object : DefaultRefreshStrategy { | ||
override fun shouldHideEmptyFolder(): Boolean = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters