@@ -239,7 +239,8 @@ class RefreshController @Inject constructor(
239
239
upToDateFolder.oldMessagesUidsToFetch.isNotEmpty() &&
240
240
maxPagesToFetch > 0
241
241
) {
242
- totalNewThreads + = fetchOnePage(scope, upToDateFolder, Direction .IN_THE_PAST ).count()
242
+ val impactedThreads = fetchOnePage(scope, upToDateFolder, Direction .IN_THE_PAST )
243
+ totalNewThreads + = impactedThreads.count { it.folderId == upToDateFolder.id }
243
244
upToDateFolder = getUpToDateFolder(folderId)
244
245
maxPagesToFetch--
245
246
}
@@ -328,12 +329,12 @@ class RefreshController @Inject constructor(
328
329
var inboxUnreadCount: Int? = null
329
330
FolderController .updateFolder(folder.id, realm = this ) { mutableRealm, it ->
330
331
331
- val allThreads = ThreadController .getThreadsByFolderId(it.id, realm = mutableRealm)
332
- it.threads.replaceContent(list = allThreads )
332
+ val allCurrentFolderThreads = ThreadController .getThreadsByFolderId(it.id, realm = mutableRealm)
333
+ it.threads.replaceContent(list = allCurrentFolderThreads )
333
334
334
- val isConversationMode = localSettings.threadMode == ThreadMode .CONVERSATION
335
335
inboxUnreadCount = updateFoldersUnreadCount(
336
- foldersIds = (if (isConversationMode) allThreads.mapTo(mutableSetOf ()) { it.folderId } else emptySet()) + folder.id,
336
+ // `impactedThreads` may not contain `folder.id` in special folders cases (i.e. snooze)
337
+ foldersIds = impactedThreads.mapTo(mutableSetOf (folder.id)) { it.folderId },
337
338
realm = mutableRealm,
338
339
)
339
340
@@ -418,31 +419,25 @@ class RefreshController @Inject constructor(
418
419
419
420
if (uids.isEmpty()) return emptySet()
420
421
421
- val impactedThreads = mutableSetOf<Thread >()
422
-
423
422
val apiResponse = delayApiCallManager.getMessagesByUids(scope, mailbox.uuid, folder.id, uids, okHttpClient)
424
423
if (! apiResponse.isSuccess()) apiResponse.throwErrorAsException()
425
424
scope.ensureActive()
426
425
427
- apiResponse.data?.messages?.let { messages ->
426
+ return apiResponse.data?.messages?.let { messages ->
427
+
428
+ return @let write {
428
429
429
- write {
430
430
val upToDateFolder = getUpToDateFolder(folder.id)
431
431
val isConversationMode = localSettings.threadMode == ThreadMode .CONVERSATION
432
- val allImpactedThreads = createThreads(scope, upToDateFolder, messages, isConversationMode)
433
432
434
- // TODO: This count will be false for INBOX & SNOOZED when the snooze feature will be implemented
435
- val messagesCount = MessageController .getMessagesCountByFolderId(upToDateFolder.id, realm = this )
436
- SentryLog .d(
437
- " Realm" ,
438
- " Saved Messages: ${upToDateFolder.displayForSentry()} | ($messagesCount )" ,
439
- )
433
+ return @write createThreads(scope, upToDateFolder, messages, isConversationMode).also {
440
434
441
- impactedThreads + = allImpactedThreads.filter { it.folderId == upToDateFolder.id }
435
+ // TODO: This count will be false for INBOX & SNOOZED when the snooze feature will be implemented
436
+ val messagesCount = MessageController .getMessagesCountByFolderId(upToDateFolder.id, realm = this )
437
+ SentryLog .d(" Realm" , " Saved Messages: ${upToDateFolder.displayForSentry()} | ($messagesCount )" )
438
+ }
442
439
}
443
- }
444
-
445
- return impactedThreads
440
+ } ? : emptySet()
446
441
}
447
442
// endregion
448
443
0 commit comments