Skip to content

Commit

Permalink
Fix calls
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Danic <mario@lovelyhq.com>
  • Loading branch information
mario committed May 16, 2018
1 parent 919e349 commit b984eea
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -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) {

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b984eea

Please sign in to comment.