Merge pull request #1229 from nextcloud/feature/apiv4/calls

[apiv4] ☎️ Calls
This commit is contained in:
Joas Schilling 2021-05-11 10:37:40 +02:00 committed by GitHub
commit 90ad596f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 62 deletions

View File

@ -70,7 +70,8 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof UserItem) { if (o instanceof UserItem) {
UserItem inItem = (UserItem) o; UserItem inItem = (UserItem) o;
return participant.getUserId().equals(inItem.getModel().getUserId()); return participant.getActorType() == inItem.getModel().getActorType() &&
participant.getActorId().equals(inItem.getModel().getActorId());
} }
return false; return false;
} }
@ -177,7 +178,7 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
.setOldController(holder.simpleDraweeView.getController()) .setOldController(holder.simpleDraweeView.getController())
.setAutoPlayAnimations(true) .setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(), .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
participant.getUserId(), R.dimen.avatar_size), null)) participant.getActorId(), R.dimen.avatar_size), null))
.build(); .build();
holder.simpleDraweeView.setController(draweeController); holder.simpleDraweeView.setController(draweeController);
} }
@ -278,7 +279,7 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
public boolean filter(String constraint) { public boolean filter(String constraint) {
return participant.getDisplayName() != null && 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.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 @Override

View File

@ -1273,7 +1273,7 @@ public class CallController extends BaseController {
inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue(); 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) ncApi.joinCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken), inCallFlag)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -1558,7 +1558,7 @@ public class CallController extends BaseController {
} }
private void hangupNetworkCalls(boolean shutDownView) { 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)) ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -1686,7 +1686,7 @@ public class CallController extends BaseController {
private void getPeersForCall() { private void getPeersForCall() {
Log.d(TAG, "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)) ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -1866,15 +1866,21 @@ public class CallController extends BaseController {
} }
} }
} else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.NICK_CHANGE)) { } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.NICK_CHANGE)) {
if (participantDisplayItems.get(sessionId) != null) {
participantDisplayItems.get(sessionId).setNick(peerConnectionEvent.getNick()); participantDisplayItems.get(sessionId).setNick(peerConnectionEvent.getNick());
}
participantsAdapter.notifyDataSetChanged(); participantsAdapter.notifyDataSetChanged();
} else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.VIDEO_CHANGE) && !isVoiceOnlyCall) { } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.VIDEO_CHANGE) && !isVoiceOnlyCall) {
if (participantDisplayItems.get(sessionId) != null) {
participantDisplayItems.get(sessionId).setStreamEnabled(peerConnectionEvent.getChangeValue()); participantDisplayItems.get(sessionId).setStreamEnabled(peerConnectionEvent.getChangeValue());
}
participantsAdapter.notifyDataSetChanged(); participantsAdapter.notifyDataSetChanged();
} else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.AUDIO_CHANGE)) { } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.AUDIO_CHANGE)) {
if (participantDisplayItems.get(sessionId) != null) {
participantDisplayItems.get(sessionId).setAudioEnabled(peerConnectionEvent.getChangeValue()); participantDisplayItems.get(sessionId).setAudioEnabled(peerConnectionEvent.getChangeValue());
}
participantsAdapter.notifyDataSetChanged(); participantsAdapter.notifyDataSetChanged();
} else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.PUBLISHER_FAILED)) { } else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.PUBLISHER_FAILED)) {
@ -2044,11 +2050,11 @@ public class CallController extends BaseController {
nick = getPeerConnectionWrapperForSessionIdAndType(session, videoStreamType, false).getNick(); nick = getPeerConnectionWrapperForSessionIdAndType(session, videoStreamType, false).getNick();
} }
String userId; String userId = "";
if (hasMCU) { if (hasMCU) {
userId = webSocketClient.getUserIdForSession(session); userId = webSocketClient.getUserIdForSession(session);
} else { } else if (participantMap.get(session).getActorType() == Participant.ActorType.USERS) {
userId = participantMap.get(session).getUserId(); userId = participantMap.get(session).getActorId();
} }
String urlForAvatar; String urlForAvatar;

View File

@ -209,7 +209,7 @@ public class CallNotificationController extends BaseController {
} }
private void checkIfAnyParticipantsRemainInRoom() { 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(), ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, userBeingCalled.getBaseUrl(),
currentConversation.getToken())) currentConversation.getToken()))
@ -230,7 +230,8 @@ public class CallNotificationController extends BaseController {
if (hasParticipantsInCall) { if (hasParticipantsInCall) {
for (Participant participant : participantList) { for (Participant participant : participantList) {
if (participant.getUserId().equals(userBeingCalled.getUserId())) { if (participant.getActorType() == Participant.ActorType.USERS &&
participant.getActorId().equals(userBeingCalled.getUserId())) {
inCallOnDifferentDevice = true; inCallOnDifferentDevice = true;
break; break;
} }

View File

@ -848,7 +848,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion,
currentUser.getBaseUrl(), currentUser.getBaseUrl(),
roomType, roomType,
userItem.getModel().getUserId(), userItem.getModel().getActorId(),
null); null);
ncApi.createRoom(credentials, ncApi.createRoom(credentials,
@ -895,15 +895,15 @@ public class ContactsController extends BaseController implements SearchView.OnQ
if ("groups".equals(participant.getSource())) { if ("groups".equals(participant.getSource())) {
if (participant.isSelected()) { if (participant.isSelected()) {
selectedGroupIds.add(participant.getUserId()); selectedGroupIds.add(participant.getActorId());
} else { } else {
selectedGroupIds.remove(participant.getUserId()); selectedGroupIds.remove(participant.getActorId());
} }
} else { } else {
if (participant.isSelected()) { if (participant.isSelected()) {
selectedUserIds.add(participant.getUserId()); selectedUserIds.add(participant.getActorId());
} else { } else {
selectedUserIds.remove(participant.getUserId()); selectedUserIds.remove(participant.getActorId());
} }
} }
@ -916,10 +916,11 @@ public class ContactsController extends BaseController implements SearchView.OnQ
Participant internalParticipant; Participant internalParticipant;
for (int i = 0; i < currentItems.size(); i++) { for (int i = 0; i < currentItems.size(); i++) {
internalParticipant = currentItems.get(i).getModel(); internalParticipant = currentItems.get(i).getModel();
if (internalParticipant.getUserId().equals(participant.getUserId()) && if (internalParticipant.getActorId().equals(participant.getActorId()) &&
"groups".equals(internalParticipant.getSource()) && internalParticipant.isSelected()) { internalParticipant.getActorType() == Participant.ActorType.GROUPS &&
internalParticipant.isSelected()) {
internalParticipant.setSelected(false); internalParticipant.setSelected(false);
selectedGroupIds.remove(internalParticipant.getUserId()); selectedGroupIds.remove(internalParticipant.getActorId());
} }
} }
@ -959,9 +960,10 @@ public class ContactsController extends BaseController implements SearchView.OnQ
for (int i = 0; i < currentItems.size(); i++) { for (int i = 0; i < currentItems.size(); i++) {
if (currentItems.get(i) instanceof UserItem) { if (currentItems.get(i) instanceof UserItem) {
internalParticipant = ((UserItem) currentItems.get(i)).getModel(); internalParticipant = ((UserItem) currentItems.get(i)).getModel();
if ("groups".equals(internalParticipant.getSource()) && internalParticipant.isSelected()) { if (internalParticipant.getActorType() == Participant.ActorType.GROUPS &&
internalParticipant.isSelected()) {
internalParticipant.setSelected(false); internalParticipant.setSelected(false);
selectedGroupIds.remove(internalParticipant.getUserId()); selectedGroupIds.remove(internalParticipant.getActorId());
} }
} }
} }

View File

@ -125,23 +125,10 @@ public class Participant {
return attendeePin; return attendeePin;
} }
@Deprecated
public String getUserId() {
if (this.actorType != null && this.actorType == ActorType.USERS) {
return this.actorId;
}
return this.userId;
}
public ParticipantType getType() { public ParticipantType getType() {
return this.type; return this.type;
} }
@Deprecated
public String getName() {
return this.name;
}
public String getDisplayName() { public String getDisplayName() {
return this.displayName; return this.displayName;
} }
@ -159,11 +146,6 @@ public class Participant {
return sessionIds; return sessionIds;
} }
@Deprecated
public long getRoomId() {
return this.roomId;
}
public Object getInCall() { public Object getInCall() {
return this.inCall; return this.inCall;
} }
@ -176,11 +158,6 @@ public class Participant {
return this.selected; return this.selected;
} }
@Deprecated
public void setUserId(String userId) {
this.userId = userId;
}
public void setAttendeeId(Long attendeeId) { public void setAttendeeId(Long attendeeId) {
this.attendeeId = attendeeId; this.attendeeId = attendeeId;
} }
@ -201,11 +178,6 @@ public class Participant {
this.type = type; this.type = type;
} }
@Deprecated
public void setName(String name) {
this.name = name;
}
public void setDisplayName(String displayName) { public void setDisplayName(String displayName) {
this.displayName = displayName; this.displayName = displayName;
} }
@ -219,11 +191,6 @@ public class Participant {
this.sessionId = sessionId; this.sessionId = sessionId;
} }
@Deprecated
public void setRoomId(long roomId) {
this.roomId = roomId;
}
public void setInCall(Object inCall) { public void setInCall(Object inCall) {
this.inCall = inCall; this.inCall = inCall;
} }

View File

@ -64,6 +64,9 @@ import okhttp3.WebSocket;
import okhttp3.WebSocketListener; import okhttp3.WebSocketListener;
import okio.ByteString; 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) @AutoInjector(NextcloudTalkApplication.class)
public class MagicWebSocketInstance extends WebSocketListener { public class MagicWebSocketInstance extends WebSocketListener {
private static final String TAG = "MagicWebSocketInstance"; private static final String TAG = "MagicWebSocketInstance";
@ -246,7 +249,14 @@ public class MagicWebSocketInstance extends WebSocketListener {
internalHashMap = joinEventMap.get(i); internalHashMap = joinEventMap.get(i);
HashMap<String, Object> userMap = (HashMap<String, Object>) internalHashMap.get("user"); HashMap<String, Object> userMap = (HashMap<String, Object>) internalHashMap.get("user");
participant = new Participant(); 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) { if (userMap != null) {
// There is no "user" attribute for guest participants. // There is no "user" attribute for guest participants.
participant.setDisplayName((String) userMap.get("displayname")); participant.setDisplayName((String) userMap.get("displayname"));
@ -399,16 +409,22 @@ public class MagicWebSocketInstance extends WebSocketListener {
} }
public String getDisplayNameForSession(String session) { public String getDisplayNameForSession(String session) {
if (usersHashMap.containsKey(session)) { Participant participant = usersHashMap.get(session);
return usersHashMap.get(session).getDisplayName(); if (participant != null) {
if (participant.getDisplayName() != null) {
return participant.getDisplayName();
}
} }
return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_nick_guest); return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_nick_guest);
} }
public String getUserIdForSession(String session) { public String getUserIdForSession(String session) {
if (usersHashMap.containsKey(session)) { Participant participant = usersHashMap.get(session);
return usersHashMap.get(session).getUserId(); if (participant != null) {
if (participant.getActorType() == USERS) {
return participant.getActorId();
}
} }
return ""; return "";