From e001d685dda7783b22dcc7fe4f24a3e6a41674dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 4 Nov 2022 17:45:28 +0100 Subject: [PATCH] Fix update of guest avatars in call participants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The URL for the avatar depends on whether the call participant is a user or a guest and, if it is a guest, on its nick. Although the user id of a participant does not change if the participant is a guest the nick may be changed during a call, so the avatar URL needs to be updated as well. As the avatar URL is fully derived from other properties it is now calculated internally in the ParticipantDisplayItem and calculated when any of the properties it depends on changes (also for the user id for completeness, as technically the item could be reused for a different participant with a different user id, even if it is not currently done). Signed-off-by: Daniel Calviño Sánchez --- .../talk/activities/CallActivity.java | 15 ++---------- .../talk/adapters/ParticipantDisplayItem.java | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 0a771ea02..507211a84 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -2382,22 +2382,11 @@ public class CallActivity extends CallBaseActivity { } } - String urlForAvatar; - if (!TextUtils.isEmpty(userId4Usage)) { - urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl, - userId4Usage, - true); - } else { - urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl, - nick, - true); - } - - ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId4Usage, + ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(baseUrl, + userId4Usage, session, connected, nick, - urlForAvatar, mediaStream, videoStreamType, videoStreamEnabled, diff --git a/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java b/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java index adc75a338..3ed18bf76 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java @@ -1,9 +1,14 @@ package com.nextcloud.talk.adapters; +import android.text.TextUtils; + +import com.nextcloud.talk.utils.ApiUtils; + import org.webrtc.EglBase; import org.webrtc.MediaStream; public class ParticipantDisplayItem { + private String baseUrl; private String userId; private String session; private boolean connected; @@ -15,16 +20,18 @@ public class ParticipantDisplayItem { private EglBase rootEglBase; private boolean isAudioEnabled; - public ParticipantDisplayItem(String userId, String session, boolean connected, String nick, String urlForAvatar, MediaStream mediaStream, String streamType, boolean streamEnabled, EglBase rootEglBase) { + public ParticipantDisplayItem(String baseUrl, String userId, String session, boolean connected, String nick, MediaStream mediaStream, String streamType, boolean streamEnabled, EglBase rootEglBase) { + this.baseUrl = baseUrl; this.userId = userId; this.session = session; this.connected = connected; this.nick = nick; - this.urlForAvatar = urlForAvatar; this.mediaStream = mediaStream; this.streamType = streamType; this.streamEnabled = streamEnabled; this.rootEglBase = rootEglBase; + + this.updateUrlForAvatar(); } public String getUserId() { @@ -33,6 +40,8 @@ public class ParticipantDisplayItem { public void setUserId(String userId) { this.userId = userId; + + this.updateUrlForAvatar(); } public String getSession() { @@ -57,14 +66,20 @@ public class ParticipantDisplayItem { public void setNick(String nick) { this.nick = nick; + + this.updateUrlForAvatar(); } public String getUrlForAvatar() { return urlForAvatar; } - public void setUrlForAvatar(String urlForAvatar) { - this.urlForAvatar = urlForAvatar; + private void updateUrlForAvatar() { + if (!TextUtils.isEmpty(userId)) { + urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl, userId, true); + } else { + urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl, nick, true); + } } public MediaStream getMediaStream() {