@@ -70,17 +70,17 @@ class ThreadController @Inject constructor(
70
70
}
71
71
72
72
/* *
73
- * Initialize and retrieve the search threads obtained from the API.
73
+ * Initialize and retrieve the search Threads obtained from the API.
74
74
* - Format the remote threads to make them compatible with the existing logic.
75
75
* - Preserve old message data if it already exists locally.
76
76
* - Handle duplicates using the existing logic.
77
- * @param remoteThreads The list of API threads that need to be processed.
78
- * @param folderRole The role of the selected folder. This is only useful when selecting the spam or trash folder .
79
- * @return A list of search threads . The search only returns messages from spam or trash if we explicitly selected those folders
77
+ * @param remoteThreads The list of API Threads that need to be processed.
78
+ * @param filterFolder The selected Folder on which we filter the Search .
79
+ * @return A list of search Threads . The search only returns Messages from SPAM or TRASH if we explicitly selected those folders
80
80
*/
81
81
suspend fun initAndGetSearchFolderThreads (
82
82
remoteThreads : List <Thread >,
83
- folderRole : FolderRole ? ,
83
+ filterFolder : Folder ? ,
84
84
): List <Thread > = withContext(ioDispatcher) {
85
85
86
86
fun MutableRealm.keepOldMessagesAndAddToSearchFolder (remoteThread : Thread , searchFolder : Folder ) {
@@ -90,12 +90,12 @@ class ThreadController @Inject constructor(
90
90
91
91
val localMessage = MessageController .getMessage(remoteMessage.uid, realm = this )
92
92
93
- // The Search only returns Messages from SPAM or TRASH if we explicitly selected those folders ,
94
- // which is the reason why we can compute `isSpam` and `isTrashed` values so loosely.
93
+ // The Search only returns Messages from TRASH if we explicitly selected this folder ,
94
+ // which is the reason why we can compute the `isTrashed` value so loosely.
95
95
remoteMessage.initLocalValues(
96
96
date = localMessage?.date ? : remoteMessage.date,
97
97
isFullyDownloaded = localMessage?.isFullyDownloaded() ? : false ,
98
- isTrashed = folderRole == FolderRole .TRASH ,
98
+ isTrashed = filterFolder?.role == FolderRole .TRASH ,
99
99
isFromSearch = localMessage == null ,
100
100
draftLocalUuid = localMessage?.draftLocalUuid,
101
101
latestCalendarEventResponse = null ,
@@ -113,7 +113,13 @@ class ThreadController @Inject constructor(
113
113
remoteThreads.map { remoteThread ->
114
114
ensureActive()
115
115
remoteThread.isFromSearch = true
116
- remoteThread.folderId = remoteThread.messages.first().folderId
116
+
117
+ val folderId = if (remoteThread.messages.count() == 1 ) {
118
+ remoteThread.messages.single().folderId
119
+ } else {
120
+ filterFolder!! .id
121
+ }
122
+ remoteThread.folderId = folderId
117
123
118
124
keepOldMessagesAndAddToSearchFolder(remoteThread, searchFolder)
119
125
0 commit comments