Fix calls

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-05-16 12:42:29 +02:00
parent 919e349ac9
commit b984eea07a
2 changed files with 58 additions and 34 deletions

View File

@ -91,7 +91,6 @@ import java.util.Date;
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 class ChatController extends BaseController implements MessagesListAdapte
@Override
public void onNext(CallOverall callOverall) {
inChat = true;
currentCall = callOverall.getOcs().getData();
startPing();
pullChatMessages(0);
currentCall = callOverall.getOcs().getData();
}
@Override
@ -410,8 +409,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
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 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
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 class ChatController extends BaseController implements MessagesListAdapte
});
} 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 class ChatController extends BaseController implements MessagesListAdapte
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 @@ public class ChatController extends BaseController implements MessagesListAdapte
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);

View File

@ -46,6 +46,7 @@ import com.nextcloud.talk.controllers.base.BaseController;
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 class OperationsMenuController extends BaseController {
.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 class OperationsMenuController extends BaseController {
.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 class OperationsMenuController extends BaseController {
}
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 class OperationsMenuController extends BaseController {
}
}
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 @@ public class OperationsMenuController extends BaseController {
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 class OperationsMenuController extends BaseController {
showResultImage(true, false);
} else {
CallOverall callOverall = (CallOverall) o;
callSession = callOverall.getOcs().getData().getSessionId();
initiateCall();
call = callOverall.getOcs().getData();
initiateConversation(true);
}
}