Skip to content

Commit 5841715

Browse files
committed
Fix code smell
1 parent c466af4 commit 5841715

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

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

+34-24
Original file line numberDiff line numberDiff line change
@@ -284,38 +284,23 @@ class ThreadController @Inject constructor(
284284
onUpdate(getThread(threadUid, realm))
285285
}
286286

287-
/**
288-
* Asynchronously fetches heavy data for a list of messages within a given mailbox and realm.
289-
*
290-
* This function fetches heavy data associated with the provided list of messages, such as attachments
291-
* or other resource-intensive content. It operates within the given realm and mailbox context.
292-
*
293-
* This function is deliberately present here as it relies on a method accessible solely through injection.
294-
*
295-
* @param messages List of messages for which heavy data needs to be fetched.
296-
* @param realm The realm context in which the heavy data fetching and updates should occur.
297-
* @param okHttpClient An optional OkHttpClient instance to use for making network requests.
298-
* If not provided, a default client will be used.
299-
*/
300-
fun fetchMessagesHeavyData(
301-
messages: List<Message>,
302-
realm: Realm,
303-
okHttpClient: OkHttpClient? = null,
304-
): Pair<List<String>, List<String>> {
305-
306-
val deletedMessagesUids = mutableListOf<String>()
307-
val failedMessagesUids = mutableListOf<String>()
308-
309-
fun fetchSwissTransferContainer(uuid: String): SwissTransferContainer? = runCatching {
287+
private fun fetchSwissTransferContainer(uuid: String): SwissTransferContainer? {
288+
return runCatching {
310289
val apiResponse = ApiRepository.getSwissTransferContainer(uuid)
311290

312291
if (apiResponse.isSuccess()) return@runCatching apiResponse.data
313292

314293
SentryLog.i(TAG, "Could not fetch SwissTransfer container")
315294
return@runCatching null
316295
}.getOrNull()
296+
}
317297

318-
val apiCallsResults = messages.mapNotNull { localMessage ->
298+
private fun getApiCallsResults(
299+
messages: List<Message>,
300+
okHttpClient: OkHttpClient?,
301+
failedMessagesUids: MutableList<String>
302+
): List<ApiCallsResults> {
303+
return messages.mapNotNull { localMessage ->
319304
return@mapNotNull runCatching {
320305
val apiResponse = ApiRepository.getMessage(localMessage.resource, okHttpClient)
321306
val swissTransferUuid = apiResponse.data?.swissTransferUuid
@@ -330,6 +315,31 @@ class ThreadController @Inject constructor(
330315
return@getOrElse null
331316
}
332317
}
318+
}
319+
320+
/**
321+
* Asynchronously fetches heavy data for a list of messages within a given mailbox and realm.
322+
*
323+
* This function fetches heavy data associated with the provided list of messages, such as attachments
324+
* or other resource-intensive content. It operates within the given realm and mailbox context.
325+
*
326+
* This function is deliberately present here as it relies on a method accessible solely through injection.
327+
*
328+
* @param messages List of messages for which heavy data needs to be fetched.
329+
* @param realm The realm context in which the heavy data fetching and updates should occur.
330+
* @param okHttpClient An optional OkHttpClient instance to use for making network requests.
331+
* If not provided, a default client will be used.
332+
*/
333+
fun fetchMessagesHeavyData(
334+
messages: List<Message>,
335+
realm: Realm,
336+
okHttpClient: OkHttpClient? = null,
337+
): Pair<List<String>, List<String>> {
338+
339+
val deletedMessagesUids = mutableListOf<String>()
340+
val failedMessagesUids = mutableListOf<String>()
341+
342+
val apiCallsResults = getApiCallsResults(messages, okHttpClient, failedMessagesUids)
333343

334344
realm.writeBlocking {
335345
var hasAttachableInThread = false

app/src/main/java/com/infomaniak/mail/data/models/thread/Thread.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class Thread : RealmObject {
9191
var isFromSearch: Boolean = false
9292
@Transient
9393
var hasAttachable: Boolean = false
94-
// Has been moved (archived, spammed, deleted, moved) but API call hasn't been done yet. Used to filter locally the Threads' list.
94+
// Has been moved (archived, spammed, deleted, moved) but API call hasn't been done yet.
95+
// It's only used to filter locally the Threads' list.
9596
@Transient
9697
var isLocallyMovedOut: Boolean = false
9798
//endregion

0 commit comments

Comments
 (0)