Skip to content

Commit

Permalink
feat: Hide snoozed folder if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX authored and KevinBoulongne committed Mar 7, 2025
1 parent 88e61ee commit 612359e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ val inboxRefreshStrategy = object : DefaultRefreshStrategy {
}
}

val scheduledDraftRefreshStrategy = object : DefaultRefreshStrategy {
override fun shouldHideEmptyFolder(): Boolean = true
}

val snoozeRefreshStrategy = object : DefaultRefreshStrategy {
override fun queryFolderThreads(folderId: String, realm: TypedRealm): List<Thread> {
return ThreadController.getInboxThreadsWithSnoozeFilter(withSnooze = true, realm = realm)
}

override fun otherFolderRolesToQueryThreads(): List<Folder.FolderRole> = listOf(Folder.FolderRole.INBOX)
override fun shouldHideEmptyFolder(): Boolean = true

override fun getMessageFromShortUid(shortUid: String, folderId: String, realm: TypedRealm): Message? {
val inboxId = FolderController.getFolder(Folder.FolderRole.INBOX, realm)?.id ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,10 @@ class RefreshController @Inject constructor(
}
}

private inline fun <reified T : MessageFlags> getMessagesUidsDelta(folderId: String, previousCursor: String): ActivitiesResult<T>? {
private inline fun <reified T : MessageFlags> getMessagesUidsDelta(
folderId: String,
previousCursor: String,
): ActivitiesResult<T>? {
return with(ApiRepository.getMessagesUidsDelta<T>(mailbox.uuid, folderId, previousCursor, okHttpClient)) {
if (!isSuccess()) throwErrorAsException()
return@with data
Expand Down Expand Up @@ -645,18 +648,23 @@ class RefreshController @Inject constructor(

getUpToDateFolder(folderId).let { currentFolder ->
currentFolder.threads.replaceContent(list = allCurrentFolderThreads)
if (currentFolder.role == FolderRole.SCHEDULED_DRAFTS) currentFolder.isDisplayed = currentFolder.threads.isNotEmpty()
if (currentFolderRefreshStrategy.shouldHideEmptyFolder()) {
currentFolder.isDisplayed = currentFolder.threads.isNotEmpty()
}
extraFolderUpdates?.invoke(currentFolder)
}

// 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 allOtherFolderThreads = otherFolder.refreshStrategy().queryFolderThreads(folderId, realm = this)
val otherFolderRefreshStrategy = otherFolder.refreshStrategy()
val allOtherFolderThreads = otherFolderRefreshStrategy.queryFolderThreads(folderId, realm = this)
otherFolder.threads.replaceContent(list = allOtherFolderThreads)

if (otherFolder.role == FolderRole.SCHEDULED_DRAFTS) otherFolder.isDisplayed = otherFolder.threads.isNotEmpty()
if (otherFolderRefreshStrategy.shouldHideEmptyFolder()) {
otherFolder.isDisplayed = otherFolder.threads.isNotEmpty()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlinx.coroutines.ensureActive
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?

Expand Down Expand Up @@ -72,6 +73,7 @@ interface DefaultRefreshStrategy : RefreshStrategy {
}

override fun otherFolderRolesToQueryThreads(): List<Folder.FolderRole> = emptyList()
override fun shouldHideEmptyFolder(): Boolean = false

override fun getMessageFromShortUid(shortUid: String, folderId: String, realm: TypedRealm): Message? {
return MessageController.getMessage(shortUid.toLongUid(folderId), realm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class Folder : RealmObject, Cloneable {
fun refreshStrategy(): RefreshStrategy = when (role) {
FolderRole.INBOX -> inboxRefreshStrategy
FolderRole.SNOOZED -> snoozeRefreshStrategy
FolderRole.SCHEDULED_DRAFTS -> scheduledDraftRefreshStrategy
else -> defaultRefreshStrategy
}

Expand Down

0 comments on commit 612359e

Please sign in to comment.