From 84f1da76ad73038b12f7b23ca5b8970afa99c7e5 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Wed, 9 Dec 2020 17:25:19 -0500 Subject: [PATCH] Fix bug where missing media keys would not always be shown on time. --- .../webrtc/CallParticipantView.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java index cec5c6b982..45285f29e9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java @@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientId; import org.thoughtcrime.securesms.util.AvatarUtil; +import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.ViewUtil; import org.webrtc.RendererCommon; @@ -49,6 +50,7 @@ public class CallParticipantView extends ConstraintLayout { private RecipientId recipientId; private boolean infoMode; + private Runnable missingMediaKeysUpdater; private AppCompatImageView backgroundAvatar; private AvatarImageView avatar; @@ -77,6 +79,7 @@ public class CallParticipantView extends ConstraintLayout { @Override protected void onFinishInflate() { super.onFinishInflate(); + backgroundAvatar = findViewById(R.id.call_participant_background_avatar); avatar = findViewById(R.id.call_participant_item_avatar); pipAvatar = findViewById(R.id.call_participant_item_pip_avatar); @@ -102,7 +105,7 @@ public class CallParticipantView extends ConstraintLayout { void setCallParticipant(@NonNull CallParticipant participant) { boolean participantChanged = recipientId == null || !recipientId.equals(participant.getRecipient().getId()); recipientId = participant.getRecipient().getId(); - infoMode = participant.getRecipient().isBlocked() || (!participant.isMediaKeysReceived() && (System.currentTimeMillis() - participant.getAddedToCallTime()) > DELAY_SHOWING_MISSING_MEDIA_KEYS); + infoMode = participant.getRecipient().isBlocked() || isMissingMediaKeys(participant); if (infoMode) { renderer.setVisibility(View.GONE); @@ -149,6 +152,28 @@ public class CallParticipantView extends ConstraintLayout { } } + private boolean isMissingMediaKeys(@NonNull CallParticipant participant) { + if (missingMediaKeysUpdater != null) { + Util.cancelRunnableOnMain(missingMediaKeysUpdater); + missingMediaKeysUpdater = null; + } + + if (!participant.isMediaKeysReceived()) { + long time = System.currentTimeMillis() - participant.getAddedToCallTime(); + if (time > DELAY_SHOWING_MISSING_MEDIA_KEYS) { + return true; + } else { + missingMediaKeysUpdater = () -> { + if (recipientId.equals(participant.getRecipient().getId())) { + setCallParticipant(participant); + } + }; + Util.runOnMainDelayed(missingMediaKeysUpdater, DELAY_SHOWING_MISSING_MEDIA_KEYS - time); + } + } + return false; + } + void setRenderInPip(boolean shouldRenderInPip) { if (infoMode) { infoMessage.setVisibility(shouldRenderInPip ? View.GONE : View.VISIBLE);