Fix incorrect mark as read behavior when leaving conversation.

This commit is contained in:
Cody Henthorne 2021-06-21 19:53:23 -04:00
parent 4932623937
commit a1aafd7453
2 changed files with 14 additions and 10 deletions

View file

@ -629,7 +629,7 @@ public class ConversationFragment extends LoggingFragment {
this.recipient = Recipient.live(conversationViewModel.getArgs().getRecipientId());
this.threadId = conversationViewModel.getArgs().getThreadId();
this.markReadHelper = new MarkReadHelper(threadId, requireContext());
this.markReadHelper = new MarkReadHelper(threadId, requireContext(), getViewLifecycleOwner());
conversationViewModel.onConversationDataAvailable(recipient.getId(), threadId, startingPosition);
messageCountsViewModel.setThreadId(threadId);
@ -806,7 +806,7 @@ public class ConversationFragment extends LoggingFragment {
snapToTopDataObserver.requestScrollPosition(0);
conversationViewModel.onConversationDataAvailable(recipient.getId(), threadId, -1);
messageCountsViewModel.setThreadId(threadId);
markReadHelper = new MarkReadHelper(threadId, requireContext());
markReadHelper = new MarkReadHelper(threadId, requireContext(), getViewLifecycleOwner());
initializeListAdapter();
initializeTypingObserver();
}

View file

@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.conversation;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
@ -25,16 +27,18 @@ class MarkReadHelper {
private final long threadId;
private final Context context;
private final LifecycleOwner lifecycleOwner;
private final Debouncer debouncer = new Debouncer(DEBOUNCE_TIMEOUT);
private long latestTimestamp;
MarkReadHelper(long threadId, @NonNull Context context) {
MarkReadHelper(long threadId, @NonNull Context context, @NonNull LifecycleOwner lifecycleOwner) {
this.threadId = threadId;
this.context = context.getApplicationContext();
this.lifecycleOwner = lifecycleOwner;
}
public void onViewsRevealed(long timestamp) {
if (timestamp <= latestTimestamp) {
if (timestamp <= latestTimestamp || lifecycleOwner.getLifecycle().getCurrentState() != Lifecycle.State.RESUMED) {
return;
}