From 3ee568213ea4279f1096ca52f4ab81954c78229e Mon Sep 17 00:00:00 2001 From: denbond7 Date: Tue, 15 Apr 2025 14:47:03 +0300 Subject: [PATCH] Refactored code --- .../api/email/gmail/GmailHistoryHandler.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailHistoryHandler.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailHistoryHandler.kt index 83abe6d70a..d18c9a76e4 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailHistoryHandler.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailHistoryHandler.kt @@ -388,6 +388,7 @@ object GmailHistoryHandler { history.labelsRemoved?.let { labelsRemoved -> for (historyLabelRemoved in labelsRemoved) { + val labelIds = historyLabelRemoved?.labelIds ?: emptyList() val historyMessageLabelIds = historyLabelRemoved?.message?.labelIds ?: emptyList() labelsToBeUpdatedMap[historyLabelRemoved.message.uid] = Pair( historyLabelRemoved.message.threadId, @@ -395,17 +396,14 @@ object GmailHistoryHandler { ) if (localFolder.isAll) { - if ( - historyLabelRemoved.labelIds?.contains(LABEL_TRASH) == true || - historyLabelRemoved.labelIds?.contains(LABEL_SPAM) == true - ) { + if (labelIds.contains(LABEL_TRASH) || labelIds.contains(LABEL_SPAM)) { deleteCandidates.remove(historyLabelRemoved.message.uid) updateCandidates.remove(historyLabelRemoved.message.uid) newCandidatesMap[historyLabelRemoved.message.uid] = historyLabelRemoved.message continue } } else { - if (localFolder.fullName in (historyLabelRemoved.labelIds ?: emptyList())) { + if (localFolder.fullName in labelIds) { newCandidatesMap.remove(historyLabelRemoved.message.uid) updateCandidates.remove(historyLabelRemoved.message.uid) deleteCandidates[historyLabelRemoved.message.uid] = @@ -413,7 +411,7 @@ object GmailHistoryHandler { continue } - if (LABEL_TRASH in (historyLabelRemoved.labelIds ?: emptyList())) { + if (LABEL_TRASH in labelIds) { val message = historyLabelRemoved.message if (localFolder.fullName in historyMessageLabelIds) { deleteCandidates.remove(message.uid) @@ -432,30 +430,29 @@ object GmailHistoryHandler { history.labelsAdded?.let { labelsAdded -> for (historyLabelAdded in labelsAdded) { + val labelIds = historyLabelAdded?.labelIds ?: emptyList() + labelsToBeUpdatedMap[historyLabelAdded.message.uid] = Pair( historyLabelAdded.message.threadId, historyLabelAdded.message.labelIds.joinToString(LABEL_IDS_SEPARATOR) ) if (localFolder.isAll) { - if ( - historyLabelAdded.labelIds?.contains(LABEL_TRASH) == true || - historyLabelAdded.labelIds?.contains(LABEL_SPAM) == true - ) { + if (labelIds.contains(LABEL_TRASH) || labelIds.contains(LABEL_SPAM)) { newCandidatesMap.remove(historyLabelAdded.message.uid) updateCandidates.remove(historyLabelAdded.message.uid) deleteCandidates[historyLabelAdded.message.uid] = historyLabelAdded.message.threadId continue } } else { - if (localFolder.fullName in (historyLabelAdded.labelIds ?: emptyList())) { + if (localFolder.fullName in labelIds) { deleteCandidates.remove(historyLabelAdded.message.uid) updateCandidates.remove(historyLabelAdded.message.uid) newCandidatesMap[historyLabelAdded.message.uid] = historyLabelAdded.message continue } - if ((historyLabelAdded.labelIds ?: emptyList()).contains(LABEL_TRASH)) { + if (labelIds.contains(LABEL_TRASH)) { newCandidatesMap.remove(historyLabelAdded.message.uid) updateCandidates.remove(historyLabelAdded.message.uid) deleteCandidates[historyLabelAdded.message.uid] = historyLabelAdded.message.threadId