Browse Source

Fix avatar when setting participant layout before receiving the data

When a new participant is found and the layout for that participant is
set up the participant data might have not been fetched yet. If that
happens the user ID can not be got from the data and therefore a guest
avatar would be shown for that participant, even if that participant is
a normal user.

However, the signaling message that is used to find new participants
already includes the user ID, so it is now explicitly given and, if not,
then it is got from the participant data (which is needed when handling
the establishment of a connection, as in that case the event does not
contain the user ID).

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Daniel Calviño Sánchez 2 years ago
parent
commit
7f86593bca
1 changed files with 27 additions and 8 deletions
  1. 27 8
      app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

+ 27 - 8
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -1835,6 +1835,7 @@ public class CallActivity extends CallBaseActivity {
         Log.d(TAG, "processUsersInRoom");
         Log.d(TAG, "processUsersInRoom");
         List<String> newSessions = new ArrayList<>();
         List<String> newSessions = new ArrayList<>();
         Set<String> oldSessions = new HashSet<>();
         Set<String> oldSessions = new HashSet<>();
+        Map<String, String> userIdsBySessionId = new HashMap<>();
 
 
         hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU();
         hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU();
         Log.d(TAG, "   hasMCU is " + hasMCU);
         Log.d(TAG, "   hasMCU is " + hasMCU);
@@ -1862,6 +1863,15 @@ public class CallActivity extends CallBaseActivity {
                 } else {
                 } else {
                     oldSessions.add(participant.get("sessionId").toString());
                     oldSessions.add(participant.get("sessionId").toString());
                 }
                 }
+
+                // The property is "userId" when not using the external signaling server and "userid" when using it.
+                String userId = null;
+                if (participant.get("userId") != null) {
+                    userId = participant.get("userId").toString();
+                } else if (participant.get("userid") != null) {
+                    userId = participant.get("userid").toString();
+                }
+                userIdsBySessionId.put(participant.get("sessionId").toString(), userId);
             } else {
             } else {
                 Log.d(TAG, "   inCallFlag of currentSessionId: " + inCallFlag);
                 Log.d(TAG, "   inCallFlag of currentSessionId: " + inCallFlag);
                 if (inCallFlag == 0 && !CallStatus.LEAVING.equals(currentCallStatus) && ApplicationWideCurrentRoomHolder.getInstance().isInCall()) {
                 if (inCallFlag == 0 && !CallStatus.LEAVING.equals(currentCallStatus) && ApplicationWideCurrentRoomHolder.getInstance().isInCall()) {
@@ -1900,10 +1910,13 @@ public class CallActivity extends CallBaseActivity {
             Log.d(TAG, "   newSession joined: " + sessionId);
             Log.d(TAG, "   newSession joined: " + sessionId);
             getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, VIDEO_STREAM_TYPE_VIDEO, false);
             getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, VIDEO_STREAM_TYPE_VIDEO, false);
 
 
+	        String userId = userIdsBySessionId.get(sessionId);
+
             runOnUiThread(() -> {
             runOnUiThread(() -> {
                 setupVideoStreamForLayout(
                 setupVideoStreamForLayout(
                     null,
                     null,
                     sessionId,
                     sessionId,
+                    userId,
                     false,
                     false,
                     VIDEO_STREAM_TYPE_VIDEO);
                     VIDEO_STREAM_TYPE_VIDEO);
             });
             });
@@ -2243,12 +2256,14 @@ public class CallActivity extends CallBaseActivity {
             setupVideoStreamForLayout(
             setupVideoStreamForLayout(
                 mediaStreamEvent.getMediaStream(),
                 mediaStreamEvent.getMediaStream(),
                 mediaStreamEvent.getSession(),
                 mediaStreamEvent.getSession(),
+                null,
                 hasAtLeastOneVideoStream,
                 hasAtLeastOneVideoStream,
                 mediaStreamEvent.getVideoStreamType());
                 mediaStreamEvent.getVideoStreamType());
         } else {
         } else {
             setupVideoStreamForLayout(
             setupVideoStreamForLayout(
                 null,
                 null,
                 mediaStreamEvent.getSession(),
                 mediaStreamEvent.getSession(),
+                null,
                 false,
                 false,
                 mediaStreamEvent.getVideoStreamType());
                 mediaStreamEvent.getVideoStreamType());
         }
         }
@@ -2339,6 +2354,7 @@ public class CallActivity extends CallBaseActivity {
 
 
     private void setupVideoStreamForLayout(@Nullable MediaStream mediaStream,
     private void setupVideoStreamForLayout(@Nullable MediaStream mediaStream,
                                            String session,
                                            String session,
+                                           String userId,
                                            boolean videoStreamEnabled,
                                            boolean videoStreamEnabled,
                                            String videoStreamType) {
                                            String videoStreamType) {
         PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(session,
         PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(session,
@@ -2358,17 +2374,20 @@ public class CallActivity extends CallBaseActivity {
             nick = peerConnectionWrapper != null ? peerConnectionWrapper.getNick() : "";
             nick = peerConnectionWrapper != null ? peerConnectionWrapper.getNick() : "";
         }
         }
 
 
-        String userId = "";
-        if (hasMCU) {
-            userId = webSocketClient.getUserIdForSession(session);
-        } else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) {
-            userId = participantMap.get(session).getCalculatedActorId();
+        String userId4Usage = userId;
+
+        if (userId4Usage == null) {
+            if (hasMCU) {
+                userId4Usage = webSocketClient.getUserIdForSession(session);
+            } else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) {
+                userId4Usage = participantMap.get(session).getCalculatedActorId();
+            }
         }
         }
 
 
         String urlForAvatar;
         String urlForAvatar;
-        if (!TextUtils.isEmpty(userId)) {
+        if (!TextUtils.isEmpty(userId4Usage)) {
             urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl,
             urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl,
-                                                    userId,
+                                                    userId4Usage,
                                                     true);
                                                     true);
         } else {
         } else {
             urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl,
             urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl,
@@ -2376,7 +2395,7 @@ public class CallActivity extends CallBaseActivity {
                                                          true);
                                                          true);
         }
         }
 
 
-        ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId,
+        ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId4Usage,
                                                                                    session,
                                                                                    session,
                                                                                    connected,
                                                                                    connected,
                                                                                    nick,
                                                                                    nick,