From ed8ac14d94b078584c94578f232f62e46ee9e3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 2 Oct 2020 01:56:32 +0200 Subject: [PATCH] Show avatar for guests in call view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The avatar of guests is based on their display name/nick. When the HPB is not used the nick is provided in the offer/answer signaling messages, and later updated through data channel messages when it changes. When the HPB is used the nick is periodically sent through data channel messages. Therefore the avatar is based on the nick set in the peer connection and reloaded when the nick changes (although it is currently a bit hacky and brittle, as it is based on whether the nick shown in the text view changed rather than whether the nick itself changed, but it works nevertheless). Note that currently it is required that the guest has a peer connection to know its nick and, therefore, its avatar; some changes would be needed in the clients to also send the nick when there is no peer connection. Signed-off-by: Daniel Calviño Sánchez --- .../talk/controllers/CallController.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java index 13dc47fb4..7f86bec98 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -1914,23 +1914,35 @@ public class CallController extends BaseController { SimpleDraweeView avatarImageView = relativeLayout.findViewById(R.id.avatarImageView); String userId; + String displayName; if (hasMCU) { userId = webSocketClient.getUserIdForSession(session); + displayName = getPeerConnectionWrapperForSessionIdAndType(session, "video", false).getNick(); } else { userId = participantMap.get(session).getUserId(); + displayName = getPeerConnectionWrapperForSessionIdAndType(session, "video", false).getNick(); } - if (!TextUtils.isEmpty(userId)) { + if (!TextUtils.isEmpty(userId) || !TextUtils.isEmpty(displayName)) { if (getActivity() != null) { avatarImageView.setController(null); + String urlForAvatar; + if (!TextUtils.isEmpty(userId)) { + urlForAvatar = ApiUtils.getUrlForAvatarWithName(baseUrl, + userId, + R.dimen.avatar_size_big); + } else { + urlForAvatar = ApiUtils.getUrlForAvatarWithNameForGuests(baseUrl, + displayName, + R.dimen.avatar_size_big); + } + DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setOldController(avatarImageView.getController()) - .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(baseUrl, - userId, - R.dimen.avatar_size_big), null)) + .setImageRequest(DisplayUtils.getImageRequestForUrl(urlForAvatar, null)) .build(); avatarImageView.setController(draweeController); } @@ -2032,13 +2044,17 @@ public class CallController extends BaseController { } private void gotNick(String sessionId, String nick, String type) { - sessionId += "+" + type; + String remoteRendererTag = sessionId + "+" + type; if (relativeLayout != null) { - RelativeLayout relativeLayout = remoteRenderersLayout.findViewWithTag(sessionId); + RelativeLayout relativeLayout = remoteRenderersLayout.findViewWithTag(remoteRendererTag); TextView textView = relativeLayout.findViewById(R.id.peer_nick_text_view); if (!textView.getText().equals(nick)) { textView.setText(nick); + + if (getActivity() != null && type.equals("video")) { + getActivity().runOnUiThread(() -> setupAvatarForSession(sessionId)); + } } } }