Skip to content

Commit 9eedc82

Browse files
refactor: Remove now useless computation of isThereDuplicatedThreads
1 parent ebc4860 commit 9eedc82

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/ThreadController.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ class ThreadController @Inject constructor(
200200
return realm.query("ANY ${Thread::messagesIds.name} IN $0", messageIds)
201201
}
202202

203-
private fun getExistingThreadsFoldersCountQuery(messageIds: Set<String>, realm: TypedRealm): RealmScalarQuery<Long> {
204-
return getThreadsByMessageIdsQuery(messageIds, realm).distinct(Thread::folderId.name).count()
205-
}
206-
207203
private fun getSearchThreadsQuery(realm: TypedRealm): RealmQuery<Thread> {
208204
return realm.query<Thread>("${Thread::isFromSearch.name} == true").sort(Thread::date.name, Sort.DESCENDING)
209205
}
@@ -266,10 +262,6 @@ class ThreadController @Inject constructor(
266262
return getThreadsByMessageIdsQuery(messageIds, realm).find()
267263
}
268264

269-
fun getExistingThreadsFoldersCount(messageIds: Set<String>, realm: TypedRealm): Long {
270-
return getExistingThreadsFoldersCountQuery(messageIds, realm).find()
271-
}
272-
273265
fun getUnreadThreadsCount(folder: Folder): Int {
274266
return getUnreadThreadsCountQuery(folder).find().toInt()
275267
}

0 commit comments

Comments
 (0)