fix: expiring messages across multi-device

This commit is contained in:
Harris 2021-09-13 13:45:55 +10:00
parent 71d2c1d1df
commit 2b6107d868
2 changed files with 25 additions and 12 deletions

View File

@ -1,16 +1,18 @@
package org.thoughtcrime.securesms.conversation.v2.components; package org.thoughtcrime.securesms.conversation.v2.components;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import network.loki.messenger.R; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.session.libsession.utilities.Util; import org.session.libsession.utilities.Util;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import network.loki.messenger.R;
public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImageView { public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImageView {
private long startedAt; private long startedAt;
@ -86,10 +88,12 @@ public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImag
long progressed = System.currentTimeMillis() - startedAt; long progressed = System.currentTimeMillis() - startedAt;
long remaining = expiresIn - progressed; long remaining = expiresIn - progressed;
if (remaining < TimeUnit.SECONDS.toMillis(30)) { if (remaining <= 0) {
return 50; return 0;
} else { } else if (remaining < TimeUnit.SECONDS.toMillis(30)) {
return 1000; return 1000;
} else {
return 5000;
} }
} }
@ -106,16 +110,20 @@ public class ExpirationTimerView extends androidx.appcompat.widget.AppCompatImag
ExpirationTimerView timerView = expirationTimerViewReference.get(); ExpirationTimerView timerView = expirationTimerViewReference.get();
if (timerView == null) return; if (timerView == null) return;
timerView.setExpirationTime(timerView.startedAt, timerView.expiresIn); long nextUpdate = timerView.calculateAnimationDelay(timerView.startedAt, timerView.expiresIn);
synchronized (timerView) { synchronized (timerView) {
if (!timerView.visible) { if (timerView.visible) {
timerView.setExpirationTime(timerView.startedAt, timerView.expiresIn);
} else {
timerView.stopped = true;
return;
}
if (nextUpdate <= 0) {
timerView.stopped = true; timerView.stopped = true;
return; return;
} }
} }
Util.runOnMainDelayed(this, nextUpdate);
Util.runOnMainDelayed(this, timerView.calculateAnimationDelay(timerView.startedAt, timerView.expiresIn));
} }
} }
} }

View File

@ -217,7 +217,9 @@ class VisibleMessageView : LinearLayout {
if (message.expireStarted + message.expiresIn <= System.currentTimeMillis()) { if (message.expireStarted + message.expiresIn <= System.currentTimeMillis()) {
ApplicationContext.getInstance(context).expiringMessageManager.checkSchedule() ApplicationContext.getInstance(context).expiringMessageManager.checkSchedule()
} }
} else if (!message.isOutgoing && !message.isMediaPending) { } else if (!message.isMediaPending) {
expirationTimerView.setPercentComplete(0.0f)
expirationTimerView.stopAnimation()
ThreadUtils.queue { ThreadUtils.queue {
val expirationManager = ApplicationContext.getInstance(context).expiringMessageManager val expirationManager = ApplicationContext.getInstance(context).expiringMessageManager
val id = message.getId() val id = message.getId()
@ -225,6 +227,9 @@ class VisibleMessageView : LinearLayout {
if (mms) DatabaseFactory.getMmsDatabase(context).markExpireStarted(id) else DatabaseFactory.getSmsDatabase(context).markExpireStarted(id) if (mms) DatabaseFactory.getMmsDatabase(context).markExpireStarted(id) else DatabaseFactory.getSmsDatabase(context).markExpireStarted(id)
expirationManager.scheduleDeletion(id, mms, message.expiresIn) expirationManager.scheduleDeletion(id, mms, message.expiresIn)
} }
} else {
expirationTimerView.stopAnimation()
expirationTimerView.setPercentComplete(0.0f)
} }
} else { } else {
expirationTimerView.isVisible = false expirationTimerView.isVisible = false