Skip to content

Commit

Permalink
feat: Keep the logic of master of simply reading message.threads to g…
Browse files Browse the repository at this point in the history
…et the list of impacted threads
  • Loading branch information
LunarX committed Mar 6, 2025
1 parent 9af6ad3 commit 2b7f41d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ val snoozeRefreshStrategy = object : DefaultRefreshStrategy {
context: Context,
mailbox: Mailbox,
realm: MutableRealm,
): Collection<Thread> {
) {
managedMessage.apply {
snoozeState = null
snoozeEndDate = null
snoozeAction = null
}

return managedMessage.threads
}

override fun addFolderToImpactedFolders(folderId: String, impactedFolders: ImpactedFolders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ class RefreshController @Inject constructor(
scope.ensureActive()

val message = currentFolderRefreshStrategy.getMessageFromShortUid(shortUid, folderId, realm = this) ?: return@forEach
threads += currentFolderRefreshStrategy.processDeletedMessage(scope, message, appContext, mailbox, realm = this)
threads += message.threads

currentFolderRefreshStrategy.processDeletedMessage(scope, message, appContext, mailbox, realm = this)
}

val impactedFolders = ImpactedFolders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.infomaniak.mail.data.models.thread.Thread
import io.realm.kotlin.MutableRealm
import io.realm.kotlin.TypedRealm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ensureActive

interface RefreshStrategy {
fun queryFolderThreads(folderId: String, realm: TypedRealm): List<Thread>
Expand All @@ -34,20 +33,18 @@ interface RefreshStrategy {

fun getMessageFromShortUid(shortUid: String, folderId: String, realm: TypedRealm): Message?

/**
* @return The list of impacted threads that have changed and need to be recomputed. The list of impacted threads will also be
* used to determine what folders need to have their unread count updated. If an extra folder needs its unread count updated
* but no thread has that extra folder as [Thread.folderId], you can define the extra folder you want inside
* [addFolderToImpactedFolders] as they will be inserted inside the list of impacted folders.
*/
fun processDeletedMessage(
scope: CoroutineScope,
managedMessage: Message,
context: Context,
mailbox: Mailbox,
realm: MutableRealm,
): Collection<Thread>
)

/**
* 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
Expand All @@ -71,19 +68,7 @@ interface DefaultRefreshStrategy : RefreshStrategy {
context: Context,
mailbox: Mailbox,
realm: MutableRealm,
): Collection<Thread> = buildSet {
/**
* This list is reversed because we'll delete items while looping over it.
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
* Looping in reverse enables us to not skip any item.
*/
managedMessage.threads.asReversed().forEach { thread ->
scope.ensureActive()

val isSuccess = thread.messages.remove(managedMessage)
if (isSuccess) add(thread)
}

) {
MessageController.deleteMessage(context, mailbox, managedMessage, realm)
}

Expand Down

0 comments on commit 2b7f41d

Please sign in to comment.