Skip to content

Commit d943942

Browse files
fix: The impactedThreadsManaged are now correctly updated
1 parent 4bb49f8 commit d943942

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class RefreshController @Inject constructor(
523523

524524
initMessageLocalValues(remoteMessage, folder)
525525
addedMessagesUids.add(remoteMessage.shortUid)
526-
impactedThreadsManaged += refreshStrategy.handleAddedMessages(scope, remoteMessage, isConversationMode, realm = this)
526+
refreshStrategy.handleAddedMessages(scope, remoteMessage, isConversationMode, impactedThreadsManaged, realm = this)
527527
}
528528

529529
addSentryBreadcrumbForAddedUidsInFolder(addedMessagesUids)

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,31 @@ interface DefaultRefreshStrategy : RefreshStrategy {
7979
scope: CoroutineScope,
8080
remoteMessage: Message,
8181
isConversationMode: Boolean,
82+
impactedThreadsManaged: MutableSet<Thread>,
8283
realm: MutableRealm,
83-
): Set<Thread> {
84-
val impactedThreads = mutableSetOf<Thread>()
84+
) {
8585
val newThread = if (isConversationMode) {
86-
val (thread, otherThreads) = realm.handleAddedMessage(scope, remoteMessage)
87-
impactedThreads += otherThreads
88-
thread
86+
realm.handleAddedMessage(scope, remoteMessage, impactedThreadsManaged)
8987
} else {
9088
remoteMessage.toThread()
9189
}
92-
newThread?.let { impactedThreads += realm.putNewThreadInRealm(it) }
93-
return impactedThreads
90+
newThread?.let { impactedThreadsManaged += realm.putNewThreadInRealm(it) }
9491
}
9592

96-
private fun MutableRealm.handleAddedMessage(scope: CoroutineScope, remoteMessage: Message): Pair<Thread?, Set<Thread>> {
93+
private fun MutableRealm.handleAddedMessage(
94+
scope: CoroutineScope,
95+
remoteMessage: Message,
96+
impactedThreadsManaged: MutableSet<Thread>,
97+
): Thread? {
9798

9899
// Other pre-existing Threads that will also require this Message and will provide the prior Messages for this new Thread.
99100
val existingThreads = ThreadController.getThreadsByMessageIds(remoteMessage.messageIds, realm = this)
100101
val existingMessages = getExistingMessages(existingThreads)
101102

102103
val thread = createNewThreadIfRequired(scope, remoteMessage, existingThreads, existingMessages)
103-
val impactedThreads = updateExistingThreads(scope, remoteMessage, existingThreads, existingMessages)
104+
updateExistingThreads(scope, remoteMessage, existingThreads, existingMessages, impactedThreadsManaged)
104105

105-
return thread to impactedThreads
106+
return thread
106107
}
107108

108109
private fun TypedRealm.createNewThreadIfRequired(
@@ -128,21 +129,17 @@ interface DefaultRefreshStrategy : RefreshStrategy {
128129
remoteMessage: Message,
129130
existingThreads: RealmResults<Thread>,
130131
existingMessages: Set<Message>,
131-
): Set<Thread> {
132-
133-
val impactedThreads = mutableSetOf<Thread>()
134-
132+
impactedThreadsManaged: MutableSet<Thread>,
133+
) {
135134
// Update already existing Threads (i.e. in other Folders, or specific cases like Snoozed)
136-
impactedThreads += addAllMessagesToAllThreads(scope, remoteMessage, existingThreads, existingMessages)
135+
impactedThreadsManaged += addAllMessagesToAllThreads(scope, remoteMessage, existingThreads, existingMessages)
137136

138137
// Some Messages don't have references to all previous Messages of the Thread (ex: these from the iOS Mail app).
139138
// Because we are missing the links between Messages, it will create multiple Threads for the same Folder.
140139
// Hence, we need to find these duplicates, and remove them.
141140
val duplicatedThreads = identifyExtraDuplicatedThreads(remoteMessage.messageIds)
142-
impactedThreads -= duplicatedThreads
141+
impactedThreadsManaged -= duplicatedThreads
143142
duplicatedThreads.forEach(::delete) // Delete the other Threads. Sorry bro, you won't be missed.
144-
145-
return impactedThreads
146143
}
147144

148145
private fun MutableRealm.addAllMessagesToAllThreads(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ interface RefreshStrategy {
6464
scope: CoroutineScope,
6565
remoteMessage: Message,
6666
isConversationMode: Boolean,
67+
impactedThreadsManaged: MutableSet<Thread>,
6768
realm: MutableRealm,
68-
): Set<Thread>
69+
)
6970
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ val snoozeRefreshStrategy = object : DefaultRefreshStrategy {
7171
scope: CoroutineScope,
7272
remoteMessage: Message,
7373
isConversationMode: Boolean,
74+
impactedThreadsManaged: MutableSet<Thread>,
7475
realm: MutableRealm,
75-
): Set<Thread> = buildSet {
76-
MessageController.updateMessage(remoteMessage.uid, realm) { localMessage ->
77-
localMessage?.snoozeState = remoteMessage.snoozeState
78-
localMessage?.snoozeEndDate = remoteMessage.snoozeEndDate
79-
localMessage?.snoozeAction = remoteMessage.snoozeAction
80-
localMessage?.threads?.let(::addAll)
76+
) {
77+
impactedThreadsManaged += buildSet {
78+
MessageController.updateMessage(remoteMessage.uid, realm) { localMessage ->
79+
localMessage?.snoozeState = remoteMessage.snoozeState
80+
localMessage?.snoozeEndDate = remoteMessage.snoozeEndDate
81+
localMessage?.snoozeAction = remoteMessage.snoozeAction
82+
localMessage?.threads?.let(::addAll)
83+
}
8184
}
8285
}
8386
}

0 commit comments

Comments
 (0)