Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Nov 26, 2024
1 parent dc9e417 commit 7c4ecf9
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object GmailHistoryHandler {
updateCandidatesMap,
labelsToBeUpdatedMap ->
val applicationContext = context.applicationContext
if (accountEntity.useConversationMode && !localFolder.isDrafts) {
if (accountEntity.useConversationMode) {
handleHistoryForConversationMode(
context = applicationContext,
accountEntity = accountEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.room.Query
import androidx.room.Transaction
import com.flowcrypt.email.api.email.FoldersManager
import com.flowcrypt.email.api.email.JavaEmailConstants
import com.flowcrypt.email.api.email.gmail.GmailApiHelper
import com.flowcrypt.email.database.MessageState
import com.flowcrypt.email.database.dao.BaseDao.Companion.doOperationViaSteps
import com.flowcrypt.email.database.dao.BaseDao.Companion.doOperationViaStepsSuspend
Expand Down Expand Up @@ -446,7 +445,6 @@ abstract class MessageDao : BaseDao<MessageEntity> {
return if (accountEntity.isGoogleSignInAccount
&& accountEntity.useAPI
&& accountEntity.useConversationMode
&& folder != GmailApiHelper.LABEL_DRAFT
) {
getNewestThread(accountEntity.email, folder)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application
val draftIdsMap: Map<String, String>
val gmailThreadInfoList: List<GmailThreadInfo>

if (accountEntity.useConversationMode && !localFolder.isDrafts) {
if (accountEntity.useConversationMode) {
val threadsResponse = GmailApiHelper.loadThreads(
context = getApplication(),
accountEntity = accountEntity,
Expand Down Expand Up @@ -544,7 +544,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application
msgs,
draftIdsMap
) { message, messageEntity ->
if (accountEntity.useConversationMode && !localFolder.isDrafts) {
if (accountEntity.useConversationMode) {
val thread = gmailThreadInfoList.firstOrNull { it.id == message.threadId }
if (thread != null) {
messageEntity.copy(
Expand Down Expand Up @@ -702,7 +702,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application

val nextPageToken: String
val gmailThreadInfoList: List<GmailThreadInfo>
val messages = if (accountEntity.useConversationMode && !localFolder.isDrafts) {
val messages = if (accountEntity.useConversationMode) {
val threadsResponse = GmailApiHelper.loadThreads(
context = getApplication(),
accountEntity = accountEntity,
Expand Down Expand Up @@ -771,7 +771,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application
localFolder.copy(fullName = JavaEmailConstants.FOLDER_SEARCH),
messages
) { message, messageEntity ->
if (accountEntity.useConversationMode && !localFolder.isDrafts) {
if (accountEntity.useConversationMode) {
val thread = gmailThreadInfoList.firstOrNull { it.id == message.threadId }
if (thread != null) {
messageEntity.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class BaseMoveMessagesWorker(context: Context, params: WorkerParameters
executeGMailAPICall(applicationContext) {
val gmailApiLabelsData = getAddAndRemoveLabelIdsForGmailAPI(folderName)

if (account.useConversationMode && folderName != GmailApiHelper.LABEL_DRAFT) {
if (account.useConversationMode) {
val resultMap = GmailApiHelper.changeLabelsForThreads(
context = applicationContext,
accountEntity = account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class ArchiveMsgsWorker(context: Context, params: WorkerParameters) :
}

private suspend fun archive(account: AccountEntity) = withContext(Dispatchers.IO) {
archiveInternal(account) { folderName, entities ->
archiveInternal(account) { _, entities ->
executeGMailAPICall(applicationContext) {
if (account.useConversationMode && folderName != GmailApiHelper.LABEL_DRAFT) {
if (account.useConversationMode) {
val resultMap = GmailApiHelper.changeLabelsForThreads(
context = applicationContext,
accountEntity = account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class DeleteMessagesPermanentlyWorker(context: Context, params: WorkerParameters
}

private suspend fun deleteMsgsPermanently(account: AccountEntity) = withContext(Dispatchers.IO) {
deleteMsgsPermanentlyInternal(account) { folderName, entities ->
deleteMsgsPermanentlyInternal(account) { _, entities ->
executeGMailAPICall(applicationContext) {
if (account.useConversationMode && folderName != GmailApiHelper.LABEL_DRAFT) {
if (account.useConversationMode) {
val resultMap = GmailApiHelper.deleteThreadsPermanently(
context = applicationContext,
accountEntity = account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class DeleteMessagesWorker(context: Context, params: WorkerParameters) :
}

private suspend fun moveMsgsToTrash(account: AccountEntity) = withContext(Dispatchers.IO) {
moveMsgsToTrashInternal(account) { folderName, entities ->
moveMsgsToTrashInternal(account) { _, entities ->
executeGMailAPICall(applicationContext) {
if (account.useConversationMode && folderName != GmailApiHelper.LABEL_DRAFT) {
if (account.useConversationMode) {
val resultMap = GmailApiHelper.moveThreadsToTrash(
context = applicationContext,
accountEntity = account,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.jetpack.workmanager.sync
Expand All @@ -19,6 +19,7 @@ import jakarta.mail.Store
/**
* @author Denys Bondarenko
*/
//need to think about this one
class SyncDraftsWorker(context: Context, params: WorkerParameters) :
BaseSyncWorker(context, params) {
override fun useIndependentConnection(): Boolean = true
Expand All @@ -28,6 +29,10 @@ class SyncDraftsWorker(context: Context, params: WorkerParameters) :
}

override suspend fun runAPIAction(accountEntity: AccountEntity) {
if (accountEntity.useConversationMode) {
return
}

val foldersManager = FoldersManager.fromDatabaseSuspend(applicationContext, accountEntity)
val folderDrafts = foldersManager.folderDrafts ?: return
val existingSyncedDrafts = roomDatabase.msgDao().getMsgsSuspend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class UpdateMsgsSeenStateWorker(context: Context, params: WorkerParameters) :

private suspend fun changeMsgsReadState(account: AccountEntity, state: MessageState) =
withContext(Dispatchers.IO) {
changeMsgsReadStateInternal(account, state) { folderName, entities ->
changeMsgsReadStateInternal(account, state) { _, entities ->
executeGMailAPICall(applicationContext) {
val removeLabelIds = if (state == MessageState.PENDING_MARK_READ) {
listOf(GmailApiHelper.LABEL_UNREAD)
Expand All @@ -72,7 +72,7 @@ class UpdateMsgsSeenStateWorker(context: Context, params: WorkerParameters) :
null
} else listOf(GmailApiHelper.LABEL_UNREAD)

if (account.useConversationMode && folderName != GmailApiHelper.LABEL_DRAFT) {
if (account.useConversationMode) {
GmailApiHelper.changeLabelsForThreads(
context = applicationContext,
accountEntity = account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(), ListPr
&& account?.useAPI == true
&& account?.useConversationMode == true
&& !isOutbox
&& !localFolder.isDrafts
) {
navController?.navigateSafe(
currentDestinationId = R.id.messagesListFragment,
Expand Down

0 comments on commit 7c4ecf9

Please sign in to comment.