diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt index 6306b1b46..8570a2191 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt @@ -6,7 +6,9 @@ package com.flowcrypt.email.jetpack.viewmodel import android.app.Application +import android.content.Context import androidx.lifecycle.viewModelScope +import com.flowcrypt.email.R import com.flowcrypt.email.api.email.FoldersManager import com.flowcrypt.email.api.email.JavaEmailConstants import com.flowcrypt.email.api.email.MsgsCacheManager @@ -31,6 +33,7 @@ import com.flowcrypt.email.ui.adapter.MessagesInThreadListAdapter import com.flowcrypt.email.ui.adapter.MessagesInThreadListAdapter.Message import com.flowcrypt.email.util.RecipientLookUpManager import com.flowcrypt.email.util.coroutines.runners.ControlledRunner +import com.flowcrypt.email.util.exception.ThreadNotFoundException import jakarta.mail.Message.RecipientType import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -388,6 +391,12 @@ class ThreadDetailsViewModel( ) ?: error("Thread not found") val threadInfo = thread.toThreadInfo(getApplication(), activeAccount) + + if (!threadInfo.labels.contains(localFolder.fullName)) { + val context: Context = getApplication() + throw ThreadNotFoundException(context.getString(R.string.thread_was_deleted_or_moved)) + } + //keep thread info updated in the local cache roomDatabase.msgDao().updateSuspend( MessageEntity.genMessageEntities( diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt index 76a314ecb..b30ee7aae 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt @@ -99,7 +99,10 @@ import com.flowcrypt.email.ui.adapter.GmailApiLabelsListAdapter import com.flowcrypt.email.ui.adapter.MessagesInThreadListAdapter import com.flowcrypt.email.ui.adapter.recyclerview.itemdecoration.SkipFirstAndLastDividerItemDecoration import com.flowcrypt.email.util.GeneralUtil +import com.flowcrypt.email.util.exception.ThreadNotFoundException +import com.google.api.client.googleapis.json.GoogleJsonResponseException import org.apache.commons.io.FilenameUtils +import java.net.HttpURLConnection /** * @author Denys Bondarenko @@ -471,6 +474,32 @@ class ThreadDetailsFragment : BaseFragment(), Prog } Result.Status.EXCEPTION -> { + val actionsForMissedThreadSituation = { + toast(getString(R.string.thread_was_deleted_or_moved)) + navController?.navigateUp() + threadDetailsViewModel.deleteThread() + } + + when (it.exception) { + is GoogleJsonResponseException -> if (it.exception.details.code == HttpURLConnection.HTTP_NOT_FOUND + && it.exception.details.errors.any { errorInfo -> + errorInfo.reason.equals("notFound", true) + } + ) { + if (isActive) { + actionsForMissedThreadSituation.invoke() + return@collect + } + } + + is ThreadNotFoundException -> { + if (isActive) { + actionsForMissedThreadSituation.invoke() + return@collect + } + } + } + if (it.data?.silentUpdate == true) { toast(it.exceptionMsg) } else { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/util/exception/ThreadNotFoundException.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/util/exception/ThreadNotFoundException.kt new file mode 100644 index 000000000..0afe26833 --- /dev/null +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/exception/ThreadNotFoundException.kt @@ -0,0 +1,11 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: denbond7 + */ + +package com.flowcrypt.email.util.exception + +/** + * @author Denys Bondarenko + */ +class ThreadNotFoundException(message: String) : FlowCryptException(message) \ No newline at end of file diff --git a/FlowCrypt/src/main/res/values-ru/strings.xml b/FlowCrypt/src/main/res/values-ru/strings.xml index e092db7dc..2eac28d55 100644 --- a/FlowCrypt/src/main/res/values-ru/strings.xml +++ b/FlowCrypt/src/main/res/values-ru/strings.xml @@ -646,6 +646,7 @@ Переписка удалена Разрешения предоставлены и теперь Вы можете загружать вложения. Удалить черновик? + Переписка удалена или перемещена Черновик Черновики(%1$d) diff --git a/FlowCrypt/src/main/res/values-uk/strings.xml b/FlowCrypt/src/main/res/values-uk/strings.xml index 0173b1fd4..fc80de5e6 100644 --- a/FlowCrypt/src/main/res/values-uk/strings.xml +++ b/FlowCrypt/src/main/res/values-uk/strings.xml @@ -647,6 +647,7 @@ Бесіду видалено Дозволи надано, і тепер ви можете завантажити вкладені файли Видалити чернетку? + Бесіду видалено або переміщено Чорновик Чорновики(%1$d) diff --git a/FlowCrypt/src/main/res/values/strings.xml b/FlowCrypt/src/main/res/values/strings.xml index 00b1f1720..9a8f831e9 100644 --- a/FlowCrypt/src/main/res/values/strings.xml +++ b/FlowCrypt/src/main/res/values/strings.xml @@ -657,6 +657,7 @@ The thread was deleted The permissions have been granted, and now you can download attachments Delete draft? + The thread was deleted or moved Draft Drafts(%1$d)