Prechádzať zdrojové kódy

Merge pull request #904 from nextcloud/fix-some-issues-related-to-guest-participants

[v8.0.x] Fix some issues related to guest participants
Biswajit Das 4 rokov pred
rodič
commit
4f83d47f51

+ 26 - 15
app/src/main/java/com/nextcloud/talk/controllers/CallController.java

@@ -1746,7 +1746,7 @@ public class CallController extends BaseController {
             }
         } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent
                 .PeerConnectionEventType.NICK_CHANGE)) {
-            gotNick(peerConnectionEvent.getSessionId(), peerConnectionEvent.getNick(), true, peerConnectionEvent.getVideoStreamType());
+            gotNick(peerConnectionEvent.getSessionId(), peerConnectionEvent.getNick(), peerConnectionEvent.getVideoStreamType());
         } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent
                 .PeerConnectionEventType.VIDEO_CHANGE) && !isVoiceOnlyCall) {
             gotAudioOrVideoChange(true, peerConnectionEvent.getSessionId() + "+" + peerConnectionEvent.getVideoStreamType(),
@@ -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);
                     }
@@ -2017,9 +2029,9 @@ public class CallController extends BaseController {
                 surfaceViewRenderer.setOnClickListener(videoOnClickListener);
                 remoteRenderersLayout.addView(relativeLayout);
                 if (hasExternalSignalingServer) {
-                    gotNick(session, webSocketClient.getDisplayNameForSession(session), false, type);
+                    gotNick(session, webSocketClient.getDisplayNameForSession(session), type);
                 } else {
-                    gotNick(session, getPeerConnectionWrapperForSessionIdAndType(session, type, false).getNick(), false, type);
+                    gotNick(session, getPeerConnectionWrapperForSessionIdAndType(session, type, false).getNick(), type);
                 }
 
                 if ("video".equals(type)) {
@@ -2031,19 +2043,18 @@ public class CallController extends BaseController {
         }
     }
 
-    private void gotNick(String sessionOrUserId, String nick, boolean isFromAnEvent, String type) {
-        if (isFromAnEvent && hasExternalSignalingServer) {
-            // get session based on userId
-            sessionOrUserId = webSocketClient.getSessionForUserId(sessionOrUserId);
-        }
-
-        sessionOrUserId += "+" + type;
+    private void gotNick(String sessionId, String nick, String type) {
+        String remoteRendererTag = sessionId + "+" + type;
 
         if (relativeLayout != null) {
-            RelativeLayout relativeLayout = remoteRenderersLayout.findViewWithTag(sessionOrUserId);
+            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));
+                }
             }
         }
     }

+ 2 - 2
app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java

@@ -271,7 +271,7 @@ public class MagicPeerConnectionWrapper {
                     if (dataChannelMessage.getPayload() instanceof String) {
                         internalNick = (String) dataChannelMessage.getPayload();
                         if (!internalNick.equals(nick)) {
-                            setNick(nick);
+                            setNick(internalNick);
                             EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
                                     .NICK_CHANGE, sessionId, getNick(), null, videoStreamType));
                         }
@@ -279,7 +279,7 @@ public class MagicPeerConnectionWrapper {
                         if (dataChannelMessage.getPayload() != null) {
                             HashMap<String, String> payloadHashMap = (HashMap<String, String>) dataChannelMessage.getPayload();
                             EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
-                                    .NICK_CHANGE, payloadHashMap.get("userid"), payloadHashMap.get("name"), null, videoStreamType));
+                                    .NICK_CHANGE, sessionId, payloadHashMap.get("name"), null, videoStreamType));
                         }
                     }
 

+ 4 - 11
app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java

@@ -247,7 +247,10 @@ public class MagicWebSocketInstance extends WebSocketListener {
                                             HashMap<String, Object> userMap = (HashMap<String, Object>) internalHashMap.get("user");
                                             participant = new Participant();
                                             participant.setUserId((String) internalHashMap.get("userid"));
-                                            participant.setDisplayName((String) userMap.get("displayname"));
+                                            if (userMap != null) {
+                                                // There is no "user" attribute for guest participants.
+                                                participant.setDisplayName((String) userMap.get("displayname"));
+                                            }
                                             usersHashMap.put((String) internalHashMap.get("sessionid"), participant);
                                         }
                                     }
@@ -403,16 +406,6 @@ public class MagicWebSocketInstance extends WebSocketListener {
         return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_nick_guest);
     }
 
-    public String getSessionForUserId(String userId) {
-        for (String session : usersHashMap.keySet()) {
-            if (userId.equals(usersHashMap.get(session).getUserId())) {
-                return session;
-            }
-        }
-
-        return "";
-    }
-
     public String getUserIdForSession(String session) {
         if (usersHashMap.containsKey(session)) {
             return usersHashMap.get(session).getUserId();