Skip to content

Commit 0e391a8

Browse files
authored
Fixed opening messages in 'All Mail' folder + fix sync in 'All Mail' folder (#3001)
* Fixed opening messages in 'All Mail' folder. |#2995 * Disabled keeping long term local cache for 'account.useConversationMode == true'.|#2995 * Fixed synchronization in 'All Mail' folder.|#2995 * Refactored code
1 parent a402126 commit 0e391a8

4 files changed

Lines changed: 70 additions & 30 deletions

File tree

FlowCrypt/src/main/java/com/flowcrypt/email/api/email/gmail/GmailHistoryHandler.kt

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.content.Context
99
import com.flowcrypt.email.R
1010
import com.flowcrypt.email.api.email.FoldersManager
1111
import com.flowcrypt.email.api.email.gmail.GmailApiHelper.Companion.LABEL_DRAFT
12+
import com.flowcrypt.email.api.email.gmail.GmailApiHelper.Companion.LABEL_SPAM
1213
import com.flowcrypt.email.api.email.gmail.GmailApiHelper.Companion.LABEL_TRASH
1314
import com.flowcrypt.email.api.email.gmail.GmailApiHelper.Companion.labelsToImapFlags
1415
import com.flowcrypt.email.api.email.gmail.api.GmaiAPIMimeMessage
@@ -128,10 +129,15 @@ object GmailHistoryHandler {
128129
val toBeDeletedLocally =
129130
gmailThreadInfoList.filter { !it.labels.contains(localFolder.fullName) }.toSet()
130131

132+
val threadIdsOfForeverDeleted =
133+
threadIdsToBeDeleted - gmailThreadInfoList.map { it.id }.toSet()
134+
131135
roomDatabase.msgDao().deleteByUIDsSuspend(
132136
account = accountEntity.email,
133137
label = localFolder.fullName,
134-
msgsUID = toBeDeletedLocally.map { Long.MAX_VALUE - it.id.toLongRadix16 })
138+
msgsUID = toBeDeletedLocally.map { Long.MAX_VALUE - it.id.toLongRadix16 }
139+
+ threadIdsOfForeverDeleted.map { Long.MAX_VALUE - it.toLongRadix16 }
140+
)
135141

136142
//need to update the left threads
137143
val toBeUpdated = gmailThreadInfoList - toBeDeletedLocally
@@ -388,21 +394,34 @@ object GmailHistoryHandler {
388394
historyMessageLabelIds.joinToString(LABEL_IDS_SEPARATOR)
389395
)
390396

391-
if (localFolder.fullName in (historyLabelRemoved.labelIds ?: emptyList())) {
392-
newCandidatesMap.remove(historyLabelRemoved.message.uid)
393-
updateCandidates.remove(historyLabelRemoved.message.uid)
394-
deleteCandidates[historyLabelRemoved.message.uid] = historyLabelRemoved.message.threadId
395-
continue
396-
}
397-
398-
if (LABEL_TRASH in (historyLabelRemoved.labelIds ?: emptyList())) {
399-
val message = historyLabelRemoved.message
400-
if (localFolder.fullName in historyMessageLabelIds) {
401-
deleteCandidates.remove(message.uid)
402-
updateCandidates.remove(message.uid)
403-
newCandidatesMap[message.uid] = message
397+
if (localFolder.isAll) {
398+
if (
399+
historyLabelRemoved.labelIds?.contains(LABEL_TRASH) == true ||
400+
historyLabelRemoved.labelIds?.contains(LABEL_SPAM) == true
401+
) {
402+
deleteCandidates.remove(historyLabelRemoved.message.uid)
403+
updateCandidates.remove(historyLabelRemoved.message.uid)
404+
newCandidatesMap[historyLabelRemoved.message.uid] = historyLabelRemoved.message
404405
continue
405406
}
407+
} else {
408+
if (localFolder.fullName in (historyLabelRemoved.labelIds ?: emptyList())) {
409+
newCandidatesMap.remove(historyLabelRemoved.message.uid)
410+
updateCandidates.remove(historyLabelRemoved.message.uid)
411+
deleteCandidates[historyLabelRemoved.message.uid] =
412+
historyLabelRemoved.message.threadId
413+
continue
414+
}
415+
416+
if (LABEL_TRASH in (historyLabelRemoved.labelIds ?: emptyList())) {
417+
val message = historyLabelRemoved.message
418+
if (localFolder.fullName in historyMessageLabelIds) {
419+
deleteCandidates.remove(message.uid)
420+
updateCandidates.remove(message.uid)
421+
newCandidatesMap[message.uid] = message
422+
continue
423+
}
424+
}
406425
}
407426

408427
val existedFlags = labelsToImapFlags(historyMessageLabelIds)
@@ -417,18 +436,31 @@ object GmailHistoryHandler {
417436
historyLabelAdded.message.threadId,
418437
historyLabelAdded.message.labelIds.joinToString(LABEL_IDS_SEPARATOR)
419438
)
420-
if (localFolder.fullName in (historyLabelAdded.labelIds ?: emptyList())) {
421-
deleteCandidates.remove(historyLabelAdded.message.uid)
422-
updateCandidates.remove(historyLabelAdded.message.uid)
423-
newCandidatesMap[historyLabelAdded.message.uid] = historyLabelAdded.message
424-
continue
425-
}
426439

427-
if ((historyLabelAdded.labelIds ?: emptyList()).contains(LABEL_TRASH)) {
428-
newCandidatesMap.remove(historyLabelAdded.message.uid)
429-
updateCandidates.remove(historyLabelAdded.message.uid)
430-
deleteCandidates[historyLabelAdded.message.uid] = historyLabelAdded.message.threadId
431-
continue
440+
if (localFolder.isAll) {
441+
if (
442+
historyLabelAdded.labelIds?.contains(LABEL_TRASH) == true ||
443+
historyLabelAdded.labelIds?.contains(LABEL_SPAM) == true
444+
) {
445+
newCandidatesMap.remove(historyLabelAdded.message.uid)
446+
updateCandidates.remove(historyLabelAdded.message.uid)
447+
deleteCandidates[historyLabelAdded.message.uid] = historyLabelAdded.message.threadId
448+
continue
449+
}
450+
} else {
451+
if (localFolder.fullName in (historyLabelAdded.labelIds ?: emptyList())) {
452+
deleteCandidates.remove(historyLabelAdded.message.uid)
453+
updateCandidates.remove(historyLabelAdded.message.uid)
454+
newCandidatesMap[historyLabelAdded.message.uid] = historyLabelAdded.message
455+
continue
456+
}
457+
458+
if ((historyLabelAdded.labelIds ?: emptyList()).contains(LABEL_TRASH)) {
459+
newCandidatesMap.remove(historyLabelAdded.message.uid)
460+
updateCandidates.remove(historyLabelAdded.message.uid)
461+
deleteCandidates[historyLabelAdded.message.uid] = historyLabelAdded.message.threadId
462+
continue
463+
}
432464
}
433465

434466
val existedFlags = labelsToImapFlags(historyLabelAdded.message.labelIds ?: emptyList())
@@ -437,6 +469,12 @@ object GmailHistoryHandler {
437469
}
438470
}
439471
}
472+
473+
deleteCandidates.keys.forEach {
474+
//we remove updates here as updating labels doesn't make sense for deleted items
475+
labelsToBeUpdatedMap.remove(it)
476+
}
477+
440478
action.invoke(
441479
deleteCandidates,
442480
newCandidatesMap,

FlowCrypt/src/main/java/com/flowcrypt/email/api/email/model/LocalFolder.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ data class LocalFolder(
5555
@IgnoredOnParcel
5656
val isTrash: Boolean = FoldersManager.FolderType.TRASH == getFolderType()
5757

58+
@IgnoredOnParcel
59+
val isInbox: Boolean = FoldersManager.FolderType.INBOX == getFolderType()
60+
5861
fun getFolderType(): FoldersManager.FolderType? {
5962
return FoldersManager.getFolderType(this)
6063
}

FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class ThreadDetailsViewModel(
390390

391391
val threadInfo = thread.toThreadInfo(getApplication(), activeAccount, localFolder)
392392

393-
if (!threadInfo.labels.contains(localFolder.fullName)) {
393+
if (!threadInfo.labels.contains(localFolder.fullName) && !localFolder.isAll) {
394394
val context: Context = getApplication()
395395
throw ThreadNotFoundException(context.getString(R.string.thread_was_deleted_or_moved))
396396
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessagesListFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,9 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(), ListPr
568568
isDraftsFolder
569569
}
570570

571-
return localFolder?.fullName.equals(
572-
JavaEmailConstants.FOLDER_INBOX,
573-
ignoreCase = true
574-
) || isOutboxFolder || checkDrafts
571+
return localFolder?.isInbox?.takeIf {
572+
account?.useConversationMode != true
573+
} == true || isOutboxFolder || checkDrafts
575574
}
576575

577576
/**

0 commit comments

Comments
 (0)