Skip to content

Commit

Permalink
refactor: Clean some code
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX authored and KevinBoulongne committed Mar 6, 2025
1 parent 5941f74 commit 0a92c13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak Mail - Android
* Copyright (C) 2022-2025 Infomaniak Network SA
* Copyright (C) 2022-2024 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,9 @@ class RefreshController @Inject constructor(
var inboxUnreadCount: Int? = null
write {
val refreshStrategy = folder.refreshStrategy()
val impactedFolders = ImpactedFolders().also {
it += handleDeletedUids(scope, activities.deletedShortUids, folder.id, refreshStrategy)
it += handleUpdatedUids(scope, activities.updatedMessages, folder.id, refreshStrategy)
}
val impactedFolders = ImpactedFolders()
impactedFolders += handleDeletedUids(scope, activities.deletedShortUids, folder.id, refreshStrategy)
impactedFolders += handleUpdatedUids(scope, activities.updatedMessages, folder.id, refreshStrategy)

inboxUnreadCount = updateFoldersUnreadCount(impactedFolders, realm = this)

Expand Down Expand Up @@ -649,12 +648,14 @@ class RefreshController @Inject constructor(
extraFolderUpdates?.invoke(currentFolder)
}

// TODO: Explain better
// Some folders such as inbox and snooze require to query again the other folder's threads as well
// Some folders such as inbox and snooze require to query again the other folder's threads as well. For example, if a
// message uid is returned as "added" or "deleted" in the snooze folder, it should disappear or appear from inbox as well.
currentFolderRefreshStrategy.otherFolderRolesToQueryThreads().forEach { folderRole ->
getUpToDateFolder(folderRole)?.let { otherFolder ->
val allThreads = otherFolder.refreshStrategy().queryFolderThreads(folderId, realm = this)
otherFolder.threads.replaceContent(list = allThreads)
val allOtherFolderThreads = otherFolder.refreshStrategy().queryFolderThreads(folderId, realm = this)
otherFolder.threads.replaceContent(list = allOtherFolderThreads)

if (otherFolder.role == FolderRole.SCHEDULED_DRAFTS) otherFolder.isDisplayed = otherFolder.threads.isNotEmpty()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import kotlinx.coroutines.ensureActive

interface RefreshStrategy {
fun queryFolderThreads(folderId: String, realm: TypedRealm): List<Thread>
fun otherFolderRolesToQueryThreads(): List<Folder.FolderRole> // TODO: Couple it tighter with queryFolderThreads()?
fun otherFolderRolesToQueryThreads(): List<Folder.FolderRole>

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 you they are inserted inside the list of impacted folders.
* [addFolderToImpactedFolders] as they will be inserted inside the list of impacted folders.
*/
fun processDeletedMessage(
scope: CoroutineScope,
Expand Down

0 comments on commit 0a92c13

Please sign in to comment.