From 335afb03dd1d6824844df2061bee77d39528b589 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 May 2021 23:06:38 +0200 Subject: [PATCH 1/5] Test calling with apiv4 Signed-off-by: Joas Schilling --- .../java/com/nextcloud/talk/controllers/CallController.java | 6 +++--- .../talk/controllers/CallNotificationController.java | 2 +- 2 files changed, 4 insertions(+), 4 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 8859e8c40..545deb1b4 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -1273,7 +1273,7 @@ public class CallController extends BaseController { inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue(); } - int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[] {1}); + int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1}); ncApi.joinCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken), inCallFlag) .subscribeOn(Schedulers.io()) @@ -1558,7 +1558,7 @@ public class CallController extends BaseController { } private void hangupNetworkCalls(boolean shutDownView) { - int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[] {1}); + int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1}); ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken)) .subscribeOn(Schedulers.io()) @@ -1686,7 +1686,7 @@ public class CallController extends BaseController { private void getPeersForCall() { Log.d(TAG, "getPeersForCall"); - int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[] {1}); + int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1}); ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken)) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java index 355bafbfb..d1f691c9b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java @@ -209,7 +209,7 @@ public class CallNotificationController extends BaseController { } private void checkIfAnyParticipantsRemainInRoom() { - int apiVersion = ApiUtils.getCallApiVersion(userBeingCalled, new int[] {1}); + int apiVersion = ApiUtils.getCallApiVersion(userBeingCalled, new int[] {ApiUtils.APIv4, 1}); ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, userBeingCalled.getBaseUrl(), currentConversation.getToken())) From dde79b5671e6e24f6aebd3fd72c9a12cc26ef2aa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 May 2021 23:44:38 +0200 Subject: [PATCH 2/5] Fix joining a call Signed-off-by: Joas Schilling --- .../nextcloud/talk/controllers/CallController.java | 6 +++--- .../talk/webrtc/MagicWebSocketInstance.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 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 545deb1b4..74abe1b4d 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -2044,11 +2044,11 @@ public class CallController extends BaseController { nick = getPeerConnectionWrapperForSessionIdAndType(session, videoStreamType, false).getNick(); } - String userId; + String userId = ""; if (hasMCU) { userId = webSocketClient.getUserIdForSession(session); - } else { - userId = participantMap.get(session).getUserId(); + } else if (participantMap.get(session).getActorType() == Participant.ActorType.USERS) { + userId = participantMap.get(session).getActorId(); } String urlForAvatar; diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index c6534dcbc..10ab6b314 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -399,16 +399,22 @@ public class MagicWebSocketInstance extends WebSocketListener { } public String getDisplayNameForSession(String session) { - if (usersHashMap.containsKey(session)) { - return usersHashMap.get(session).getDisplayName(); + Participant participant = usersHashMap.get(session); + if (participant != null) { + if (participant.getDisplayName() != null) { + return participant.getDisplayName(); + } } return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_nick_guest); } public String getUserIdForSession(String session) { - if (usersHashMap.containsKey(session)) { - return usersHashMap.get(session).getUserId(); + Participant participant = usersHashMap.get(session); + if (participant != null) { + if (participant.getActorType() == Participant.ActorType.USERS) { + return participant.getActorId(); + } } return ""; From 79be7534931637dfc750c10d72ab16238bdbb6d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 10 May 2021 11:34:19 +0200 Subject: [PATCH 3/5] Fix some more getUserId() calls Signed-off-by: Joas Schilling --- .../talk/adapters/items/UserItem.java | 7 ++-- .../CallNotificationController.java | 3 +- .../talk/controllers/ContactsController.java | 22 +++++++------ .../models/json/participants/Participant.java | 33 ------------------- .../talk/webrtc/MagicWebSocketInstance.java | 14 ++++++-- 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java index c1dfe7bf1..4eeb94819 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java @@ -70,7 +70,8 @@ public class UserItem extends AbstractFlexibleItem public boolean equals(Object o) { if (o instanceof UserItem) { UserItem inItem = (UserItem) o; - return participant.getUserId().equals(inItem.getModel().getUserId()); + return participant.getActorType().equals(inItem.getModel().getActorType()) && + participant.getActorId().equals(inItem.getModel().getActorId()); } return false; } @@ -178,7 +179,7 @@ public class UserItem extends AbstractFlexibleItem .setOldController(holder.simpleDraweeView.getController()) .setAutoPlayAnimations(true) .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(), - participant.getUserId(), R.dimen.avatar_size), null)) + participant.getActorId(), R.dimen.avatar_size), null)) .build(); holder.simpleDraweeView.setController(draweeController); } @@ -279,7 +280,7 @@ public class UserItem extends AbstractFlexibleItem public boolean filter(String constraint) { return participant.getDisplayName() != null && (Pattern.compile(constraint, Pattern.CASE_INSENSITIVE | Pattern.LITERAL).matcher(participant.getDisplayName().trim()).find() || - Pattern.compile(constraint, Pattern.CASE_INSENSITIVE | Pattern.LITERAL).matcher(participant.getUserId().trim()).find()); + Pattern.compile(constraint, Pattern.CASE_INSENSITIVE | Pattern.LITERAL).matcher(participant.getActorId().trim()).find()); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java index d1f691c9b..1095ff051 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java @@ -230,7 +230,8 @@ public class CallNotificationController extends BaseController { if (hasParticipantsInCall) { for (Participant participant : participantList) { - if (participant.getUserId().equals(userBeingCalled.getUserId())) { + if (participant.getActorType() == Participant.ActorType.USERS && + participant.getActorId().equals(userBeingCalled.getUserId())) { inCallOnDifferentDevice = true; break; } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index fc9d2d8ce..8ef91b3dd 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -862,7 +862,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, currentUser.getBaseUrl(), roomType, - userItem.getModel().getUserId(), + userItem.getModel().getActorId(), null); ncApi.createRoom(credentials, @@ -914,15 +914,15 @@ public class ContactsController extends BaseController implements SearchView.OnQ if ("groups".equals(participant.getSource())) { if (participant.isSelected()) { - selectedGroupIds.add(participant.getUserId()); + selectedGroupIds.add(participant.getActorId()); } else { - selectedGroupIds.remove(participant.getUserId()); + selectedGroupIds.remove(participant.getActorId()); } } else { if (participant.isSelected()) { - selectedUserIds.add(participant.getUserId()); + selectedUserIds.add(participant.getActorId()); } else { - selectedUserIds.remove(participant.getUserId()); + selectedUserIds.remove(participant.getActorId()); } } @@ -935,10 +935,11 @@ public class ContactsController extends BaseController implements SearchView.OnQ Participant internalParticipant; for (int i = 0; i < currentItems.size(); i++) { internalParticipant = currentItems.get(i).getModel(); - if (internalParticipant.getUserId().equals(participant.getUserId()) && - "groups".equals(internalParticipant.getSource()) && internalParticipant.isSelected()) { + if (internalParticipant.getActorId().equals(participant.getActorId()) && + internalParticipant.getActorType() == Participant.ActorType.GROUPS && + internalParticipant.isSelected()) { internalParticipant.setSelected(false); - selectedGroupIds.remove(internalParticipant.getUserId()); + selectedGroupIds.remove(internalParticipant.getActorId()); } } @@ -978,9 +979,10 @@ public class ContactsController extends BaseController implements SearchView.OnQ for (int i = 0; i < currentItems.size(); i++) { if (currentItems.get(i) instanceof UserItem) { internalParticipant = ((UserItem) currentItems.get(i)).getModel(); - if ("groups".equals(internalParticipant.getSource()) && internalParticipant.isSelected()) { + if (internalParticipant.getActorType() == Participant.ActorType.GROUPS && + internalParticipant.isSelected()) { internalParticipant.setSelected(false); - selectedGroupIds.remove(internalParticipant.getUserId()); + selectedGroupIds.remove(internalParticipant.getActorId()); } } } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java index 71a9db829..ffd74e34e 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java @@ -125,23 +125,10 @@ public class Participant { return attendeePin; } - @Deprecated - public String getUserId() { - if (this.actorType != null && this.actorType == ActorType.USERS) { - return this.actorId; - } - return this.userId; - } - public ParticipantType getType() { return this.type; } - @Deprecated - public String getName() { - return this.name; - } - public String getDisplayName() { return this.displayName; } @@ -159,11 +146,6 @@ public class Participant { return sessionIds; } - @Deprecated - public long getRoomId() { - return this.roomId; - } - public Object getInCall() { return this.inCall; } @@ -176,11 +158,6 @@ public class Participant { return this.selected; } - @Deprecated - public void setUserId(String userId) { - this.userId = userId; - } - public void setAttendeeId(Long attendeeId) { this.attendeeId = attendeeId; } @@ -201,11 +178,6 @@ public class Participant { this.type = type; } - @Deprecated - public void setName(String name) { - this.name = name; - } - public void setDisplayName(String displayName) { this.displayName = displayName; } @@ -219,11 +191,6 @@ public class Participant { this.sessionId = sessionId; } - @Deprecated - public void setRoomId(long roomId) { - this.roomId = roomId; - } - public void setInCall(Object inCall) { this.inCall = inCall; } diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index 10ab6b314..70756bc87 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -64,6 +64,9 @@ import okhttp3.WebSocket; import okhttp3.WebSocketListener; import okio.ByteString; +import static com.nextcloud.talk.models.json.participants.Participant.ActorType.GUESTS; +import static com.nextcloud.talk.models.json.participants.Participant.ActorType.USERS; + @AutoInjector(NextcloudTalkApplication.class) public class MagicWebSocketInstance extends WebSocketListener { private static final String TAG = "MagicWebSocketInstance"; @@ -246,7 +249,14 @@ public class MagicWebSocketInstance extends WebSocketListener { internalHashMap = joinEventMap.get(i); HashMap userMap = (HashMap) internalHashMap.get("user"); participant = new Participant(); - participant.setUserId((String) internalHashMap.get("userid")); + String userId = (String) internalHashMap.get("userid"); + if (userId != null) { + participant.setActorType(USERS); + participant.setActorId(userId); + } else { + participant.setActorType(GUESTS); + // FIXME seems to be not given by the HPB: participant.setActorId(); + } if (userMap != null) { // There is no "user" attribute for guest participants. participant.setDisplayName((String) userMap.get("displayname")); @@ -412,7 +422,7 @@ public class MagicWebSocketInstance extends WebSocketListener { public String getUserIdForSession(String session) { Participant participant = usersHashMap.get(session); if (participant != null) { - if (participant.getActorType() == Participant.ActorType.USERS) { + if (participant.getActorType() == USERS) { return participant.getActorId(); } } From 112a5662adeeb6f31ed6495f737c068c0a6ffb28 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 10 May 2021 11:47:09 +0200 Subject: [PATCH 4/5] Fix null reference when a participant leaves java.lang.NullPointerException: Attempt to invoke virtual method 'void com.nextcloud.talk.adapters.ParticipantDisplayItem.setAudioEnabled(boolean)' on a null object reference Signed-off-by: Joas Schilling --- .../nextcloud/talk/controllers/CallController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 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 74abe1b4d..db683cc2e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -1866,15 +1866,21 @@ public class CallController extends BaseController { } } } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.NICK_CHANGE)) { - participantDisplayItems.get(sessionId).setNick(peerConnectionEvent.getNick()); + if (participantDisplayItems.get(sessionId) != null) { + participantDisplayItems.get(sessionId).setNick(peerConnectionEvent.getNick()); + } participantsAdapter.notifyDataSetChanged(); } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.VIDEO_CHANGE) && !isVoiceOnlyCall) { - participantDisplayItems.get(sessionId).setStreamEnabled(peerConnectionEvent.getChangeValue()); + if (participantDisplayItems.get(sessionId) != null) { + participantDisplayItems.get(sessionId).setStreamEnabled(peerConnectionEvent.getChangeValue()); + } participantsAdapter.notifyDataSetChanged(); } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.AUDIO_CHANGE)) { - participantDisplayItems.get(sessionId).setAudioEnabled(peerConnectionEvent.getChangeValue()); + if (participantDisplayItems.get(sessionId) != null) { + participantDisplayItems.get(sessionId).setAudioEnabled(peerConnectionEvent.getChangeValue()); + } participantsAdapter.notifyDataSetChanged(); } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.PUBLISHER_FAILED)) { From 72705dbaf528109fc4456e037df427cf5e01227b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 10 May 2021 12:36:19 +0200 Subject: [PATCH 5/5] Fix "calls equals on an enum instance" Signed-off-by: Joas Schilling --- .../main/java/com/nextcloud/talk/adapters/items/UserItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java index 4eeb94819..cb5614777 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java @@ -70,7 +70,7 @@ public class UserItem extends AbstractFlexibleItem public boolean equals(Object o) { if (o instanceof UserItem) { UserItem inItem = (UserItem) o; - return participant.getActorType().equals(inItem.getModel().getActorType()) && + return participant.getActorType() == inItem.getModel().getActorType() && participant.getActorId().equals(inItem.getModel().getActorId()); } return false;