@@ -562,30 +562,13 @@ class RefreshController @Inject constructor(
562562 // Other pre-existing Threads that will also require this Message and will provide the prior Messages for this new Thread.
563563 val existingThreads = ThreadController .getThreadsByMessageIds(remoteMessage.messageIds, realm = this )
564564 val existingMessages = getExistingMessages(existingThreads)
565- // Some Messages don't have references to all previous Messages of the Thread (ex: these from the iOS Mail app).
566- // Because we are missing the links between Messages, it will create multiple Threads for the same Folder.
567- // Hence, we need to find these duplicates.
568- // TODO: Find a way to compute this boolean in `updateExistingThreads()` if possible
569- val isThereDuplicatedThreads = isThereDuplicatedThreads(remoteMessage.messageIds, existingThreads.count())
570565
571566 val thread = createNewThreadIfRequired(scope, remoteMessage, existingThreads, existingMessages)
572-
573- val impactedThreads = updateExistingThreads(
574- scope = scope,
575- remoteMessage = remoteMessage,
576- existingThreads = existingThreads,
577- existingMessages = existingMessages,
578- isThereDuplicatedThreads = isThereDuplicatedThreads,
579- )
567+ val impactedThreads = updateExistingThreads(scope, remoteMessage, existingThreads, existingMessages)
580568
581569 return thread to impactedThreads
582570 }
583571
584- private fun MutableRealm.isThereDuplicatedThreads (messageIds : RealmSet <String >, threadsCount : Int ): Boolean {
585- val foldersCount = ThreadController .getExistingThreadsFoldersCount(messageIds, realm = this )
586- return foldersCount != threadsCount.toLong()
587- }
588-
589572 private fun TypedRealm.createNewThreadIfRequired (
590573 scope : CoroutineScope ,
591574 newMessage : Message ,
@@ -609,20 +592,19 @@ class RefreshController @Inject constructor(
609592 remoteMessage : Message ,
610593 existingThreads : RealmResults <Thread >,
611594 existingMessages : Set <Message >,
612- isThereDuplicatedThreads : Boolean ,
613595 ): Set <Thread > {
614596
615597 val impactedThreads = mutableSetOf<Thread >()
616598
617599 // Update already existing Threads (i.e. in other Folders, or specific cases like Snoozed)
618600 impactedThreads + = addAllMessagesToAllThreads(scope, remoteMessage, existingThreads, existingMessages)
619601
620- // Now that all existing Threads are updated, we need to remove the duplicated Threads .
621- if (isThereDuplicatedThreads) {
622- val duplicatedThreads = identifyExtraDuplicatedThreads(remoteMessage.messageIds)
623- impactedThreads - = duplicatedThreads
624- duplicatedThreads.forEach(::delete) // Delete the other Threads. Sorry bro, you won't be missed.
625- }
602+ // Some Messages don't have references to all previous Messages of the Thread (ex: these from the iOS Mail app) .
603+ // Because we are missing the links between Messages, it will create multiple Threads for the same Folder.
604+ // Hence, we need to find these duplicates, and remove them.
605+ val duplicatedThreads = identifyExtraDuplicatedThreads(remoteMessage.messageIds)
606+ impactedThreads - = duplicatedThreads
607+ duplicatedThreads.forEach(::delete) // Delete the other Threads. Sorry bro, you won't be missed.
626608
627609 return impactedThreads
628610 }
0 commit comments