Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated Draft folder refresh #1715

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ class MainActivity : BaseActivity() {
* We want to scheduleWork after a delay in the off chance where we came back from NewMessageActivity while an Activity
* recreation got triggered.
*
* We need to give time to the NewMessageActivity to save the last state of the draft in realm and then scheduleWork on its
* own. Not waiting would scheduleWork before NewMessageActivity has time to write to realm and schedule its own worker. This
* would result in an attempt to save any temporary draft saved to realm because of saveDraftDebouncing() effectively sending
* a second unwanted draft.
* We need to give time to the NewMessageActivity to save the last state of the draft in Realm and then scheduleWork on its
* own. Not waiting would scheduleWork before NewMessageActivity has time to write to Realm and schedule its own worker. This
* would result in an attempt to save any temporary Draft saved to Realm because of saveDraftDebouncing() effectively sending
* a second unwanted Draft.
*/
private fun scheduleDraftActionsWorkWithDelay() = lifecycleScope.launch(Dispatchers.IO) {
delay(1_000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ import com.infomaniak.mail.utils.RealmChangesBinding.Companion.bindResultsChange
import com.infomaniak.mail.utils.UiUtils.formatUnreadCount
import com.infomaniak.mail.utils.Utils.isPermanentDeleteFolder
import com.infomaniak.mail.utils.Utils.runCatchingRealm
import com.infomaniak.mail.utils.WorkerUtils
import com.infomaniak.mail.utils.extensions.*
import com.infomaniak.mail.workers.DraftsActionsWorker
import dagger.hilt.android.AndroidEntryPoint
import io.realm.kotlin.ext.isValid
import io.sentry.Sentry
import io.sentry.SentryLevel
import java.util.Date
Expand Down Expand Up @@ -107,9 +104,6 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
@Inject
lateinit var localSettings: LocalSettings

@Inject
lateinit var draftsActionsWorkerScheduler: DraftsActionsWorker.Scheduler

@Inject
lateinit var notificationManagerCompat: NotificationManagerCompat

Expand Down Expand Up @@ -163,7 +157,6 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
observeCurrentFolder()
observeCurrentFolderLive()
observeUpdatedAtTriggers()
observerDraftsActionsCompletedWorks()
observeFlushFolderTrigger()
observeUpdateInstall()
}.getOrDefault(Unit)
Expand Down Expand Up @@ -617,19 +610,6 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
threadListViewModel.updatedAtTrigger.observe(viewLifecycleOwner) { updateUpdatedAt() }
}

private fun observerDraftsActionsCompletedWorks() {

fun observeDraftsActions() {
draftsActionsWorkerScheduler.getCompletedWorkInfoLiveData().observe(viewLifecycleOwner) {
mainViewModel.currentFolder.value?.let { folder ->
if (folder.isValid() && folder.role == FolderRole.DRAFT) mainViewModel.forceRefreshThreads()
}
}
}

WorkerUtils.flushWorkersBefore(requireContext(), viewLifecycleOwner, ::observeDraftsActions)
}

private fun observeFlushFolderTrigger() {
mainViewModel.flushFolderTrigger.observe(viewLifecycleOwner) { descriptionDialog.resetLoadingAndDismiss() }
}
Expand Down
Loading