Skip to content

Commit

Permalink
fix: Put back other folders' unread count updates (#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne authored Feb 27, 2025
2 parents 062a219 + 7c65a73 commit b3da5cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ class RefreshController @Inject constructor(
upToDateFolder.oldMessagesUidsToFetch.isNotEmpty() &&
maxPagesToFetch > 0
) {
totalNewThreads += fetchOnePage(scope, upToDateFolder, Direction.IN_THE_PAST).count()
val impactedThreads = fetchOnePage(scope, upToDateFolder, Direction.IN_THE_PAST)
totalNewThreads += impactedThreads.count { it.folderId == upToDateFolder.id }
upToDateFolder = getUpToDateFolder(folderId)
maxPagesToFetch--
}
Expand Down Expand Up @@ -328,12 +329,12 @@ class RefreshController @Inject constructor(
var inboxUnreadCount: Int? = null
FolderController.updateFolder(folder.id, realm = this) { mutableRealm, it ->

val allThreads = ThreadController.getThreadsByFolderId(it.id, realm = mutableRealm)
it.threads.replaceContent(list = allThreads)
val allCurrentFolderThreads = ThreadController.getThreadsByFolderId(it.id, realm = mutableRealm)
it.threads.replaceContent(list = allCurrentFolderThreads)

val isConversationMode = localSettings.threadMode == ThreadMode.CONVERSATION
inboxUnreadCount = updateFoldersUnreadCount(
foldersIds = (if (isConversationMode) allThreads.mapTo(mutableSetOf()) { it.folderId } else emptySet()) + folder.id,
// `impactedThreads` may not contain `folder.id` in special folders cases (i.e. snooze)
foldersIds = impactedThreads.mapTo(mutableSetOf(folder.id)) { it.folderId },
realm = mutableRealm,
)

Expand Down Expand Up @@ -418,31 +419,25 @@ class RefreshController @Inject constructor(

if (uids.isEmpty()) return emptySet()

val impactedThreads = mutableSetOf<Thread>()

val apiResponse = delayApiCallManager.getMessagesByUids(scope, mailbox.uuid, folder.id, uids, okHttpClient)
if (!apiResponse.isSuccess()) apiResponse.throwErrorAsException()
scope.ensureActive()

apiResponse.data?.messages?.let { messages ->
return apiResponse.data?.messages?.let { messages ->

return@let write {

write {
val upToDateFolder = getUpToDateFolder(folder.id)
val isConversationMode = localSettings.threadMode == ThreadMode.CONVERSATION
val allImpactedThreads = createThreads(scope, upToDateFolder, messages, isConversationMode)

// TODO: This count will be false for INBOX & SNOOZED when the snooze feature will be implemented
val messagesCount = MessageController.getMessagesCountByFolderId(upToDateFolder.id, realm = this)
SentryLog.d(
"Realm",
"Saved Messages: ${upToDateFolder.displayForSentry()} | ($messagesCount)",
)
return@write createThreads(scope, upToDateFolder, messages, isConversationMode).also {

impactedThreads += allImpactedThreads.filter { it.folderId == upToDateFolder.id }
// TODO: This count will be false for INBOX & SNOOZED when the snooze feature will be implemented
val messagesCount = MessageController.getMessagesCountByFolderId(upToDateFolder.id, realm = this)
SentryLog.d("Realm", "Saved Messages: ${upToDateFolder.displayForSentry()} | ($messagesCount)")
}
}
}

return impactedThreads
} ?: emptySet()
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class FetchMessagesManager @Inject constructor(
return
}

return@let threads.toList()
return@let threads.filter { it.folderId == folder.id }.toList()
}

SentryLog.d(TAG, "LaunchWork: ${mailbox.email} has ${threadsWithNewMessages.count()} Threads with new Messages")
Expand Down

0 comments on commit b3da5cb

Please sign in to comment.