Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hide empty snooze folder #2226

Open
wants to merge 1 commit into
base: display-snooze-thread-count-over-unread
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -554,7 +554,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 @@ -644,18 +647,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