From b984eea07a51a2f029ebd823de480bd1a8df0887 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 16 May 2018 12:42:29 +0200 Subject: [PATCH] Fix calls Signed-off-by: Mario Danic --- .../talk/controllers/ChatController.java | 24 ++++--- .../bottomsheet/OperationsMenuController.java | 68 ++++++++++++------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java index 56a2738a99..5a726c9be8 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java @@ -91,7 +91,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.TimeUnit; import javax.inject.Inject; @@ -382,9 +381,9 @@ public void onSubscribe(Disposable d) { @Override public void onNext(CallOverall callOverall) { inChat = true; + currentCall = callOverall.getOcs().getData(); startPing(); pullChatMessages(0); - currentCall = callOverall.getOcs().getData(); } @Override @@ -410,8 +409,7 @@ private void sendMessage(String message) { fieldMap.put("actorDisplayName", conversationUser.getDisplayName()); - ncApi.sendChatMessage(ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken()), - ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap) + ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .retry(3, observable -> inChat) @@ -492,8 +490,7 @@ private void pullChatMessages(int lookIntoFuture) { } if (lookIntoFuture == 1) { - ncApi.pullChatMessages(ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken()), - ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap) + ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .takeWhile(observable -> inChat) @@ -521,8 +518,8 @@ public void onComplete() { }); } else { - ncApi.pullChatMessages(ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken()), - ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap) + ncApi.pullChatMessages(credentials, + ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .retry(3, observable -> inChat) @@ -652,10 +649,16 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { return true; case R.id.conversation_video_call: - startActivity(Objects.requireNonNull(getIntentForCall(false))); + Intent videoCallIntent = getIntentForCall(false); + if (videoCallIntent != null) { + startActivity(videoCallIntent); + } return true; case R.id.conversation_voice_call: - startActivity(Objects.requireNonNull(getIntentForCall(true))); + Intent voiceCallIntent = getIntentForCall(true); + if (voiceCallIntent != null) { + startActivity(voiceCallIntent); + } return true; default: @@ -669,6 +672,7 @@ private Intent getIntentForCall(boolean isVoiceOnlyCall) { bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser)); bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId()); + bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); if (isVoiceOnlyCall) { bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java index 7f8829288f..e257e4284a 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java @@ -46,6 +46,7 @@ import com.nextcloud.talk.events.BottomSheetLockEvent; import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.models.database.UserEntity; +import com.nextcloud.talk.models.json.call.Call; import com.nextcloud.talk.models.json.call.CallOverall; import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall; import com.nextcloud.talk.models.json.generic.GenericOverall; @@ -108,7 +109,7 @@ public class OperationsMenuController extends BaseController { private String callUrl; private String baseUrl; - private String callSession; + private Call call; private String conversationToken; private Disposable disposable; @@ -427,7 +428,7 @@ public void onNext(CapabilitiesOverall capabilitiesOverall) { .getCapabilities().getSpreedCapability() .getFeatures() != null && capabilitiesOverall.getOcs().getData() .getCapabilities().getSpreedCapability() - .getFeatures().contains("guest-signaling")) { + .getFeatures().contains("chat-v2")) { if (room.isHasPassword() && room.isGuest()) { eventBus.post(new BottomSheetLockEvent(true, 0, true, false)); @@ -439,8 +440,16 @@ public void onNext(CapabilitiesOverall capabilitiesOverall) { .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); } else { - initiateCall(); + initiateConversation(true); } + } else if (capabilitiesOverall.getOcs().getData() + .getCapabilities().getSpreedCapability() != null && + capabilitiesOverall.getOcs().getData() + .getCapabilities().getSpreedCapability() + .getFeatures() != null && capabilitiesOverall.getOcs().getData() + .getCapabilities().getSpreedCapability() + .getFeatures().contains("guest-signaling")) { + initiateCall(); } else { showResultImage(false, true); } @@ -494,24 +503,7 @@ public void onComplete() { } if (localInvitedUsers.size() == 0) { - if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { - eventBus.post(new BottomSheetLockEvent(true, 0, - true, true, false)); - - Intent conversationIntent = new Intent(getActivity(), CallActivity.class); - Bundle bundle = new Bundle(); - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken()); - bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName()); - bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser)); - conversationIntent.putExtras(bundle); - getParentController().getRouter().pushController((RouterTransaction.with( - new ChatController(bundle)).pushChangeHandler( - new HorizontalChangeHandler()) - .popChangeHandler(new HorizontalChangeHandler()))); - - } else { - initiateCall(); - } + initiateConversation(false); } dispose(); } @@ -522,6 +514,34 @@ public void onComplete() { } } + private void initiateConversation(boolean dismissView) { + if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { + eventBus.post(new BottomSheetLockEvent(true, 0, + true, true, dismissView)); + + Intent conversationIntent = new Intent(getActivity(), CallActivity.class); + Bundle bundle = new Bundle(); + bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken()); + bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName()); + bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser)); + if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) { + bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); + } + + bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call)); + + conversationIntent.putExtras(bundle); + getParentController().getParentController().getRouter().pushController((RouterTransaction.with( + new ChatController(bundle)).pushChangeHandler( + new HorizontalChangeHandler()) + .popChangeHandler(new HorizontalChangeHandler()))); + + } else { + initiateCall(); + } + } + + private void initiateCall() { eventBus.post(new BottomSheetLockEvent(true, 0, true, true)); Bundle bundle = new Bundle(); @@ -530,7 +550,7 @@ private void initiateCall() { if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) { bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); } - bundle.putString(BundleKeys.KEY_CALL_SESSION, callSession); + bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call)); if (getActivity() != null) { @@ -561,8 +581,8 @@ public void onNext(Object o) { showResultImage(true, false); } else { CallOverall callOverall = (CallOverall) o; - callSession = callOverall.getOcs().getData().getSessionId(); - initiateCall(); + call = callOverall.getOcs().getData(); + initiateConversation(true); } }