"chat-v2" capability is available since Nextcloud 13

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-08 14:27:01 +02:00
parent dab9a7c860
commit 172d8da1cf
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
6 changed files with 77 additions and 131 deletions

View File

@ -25,7 +25,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.provider.ContactsContract import android.provider.ContactsContract
import android.text.TextUtils import android.text.TextUtils
import android.view.ViewGroup import android.view.ViewGroup
@ -244,12 +243,11 @@ class MainActivity : BaseActivity(), ActionBarProvider {
.subscribe(object : Observer<RoomOverall> { .subscribe(object : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) {} override fun onSubscribe(d: Disposable) {}
override fun onNext(roomOverall: RoomOverall) { override fun onNext(roomOverall: RoomOverall) {
val conversationIntent = Intent(context, MagicCallActivity::class.java)
val bundle = Bundle() val bundle = Bundle()
bundle.putParcelable(KEY_USER_ENTITY, currentUser) bundle.putParcelable(KEY_USER_ENTITY, currentUser)
bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs.data.token) bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs.data.token)
bundle.putString(KEY_ROOM_ID, roomOverall.ocs.data.roomId) bundle.putString(KEY_ROOM_ID, roomOverall.ocs.data.roomId)
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
// FIXME once APIv2 or later is used only, the createRoom already returns all the data // FIXME once APIv2 or later is used only, the createRoom already returns all the data
ncApi.getRoom( ncApi.getRoom(
credentials, credentials,
@ -277,18 +275,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
override fun onError(e: Throwable) {} override fun onError(e: Throwable) {}
override fun onComplete() {} override fun onComplete() {}
}) })
} else {
conversationIntent.putExtras(bundle)
startActivity(conversationIntent)
Handler().postDelayed(
{
if (!isDestroyed) {
router!!.popCurrentController()
}
},
100
)
}
} }
override fun onError(e: Throwable) {} override fun onError(e: Throwable) {}

View File

@ -1777,7 +1777,6 @@ class ChatController(args: Bundle) :
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.ocs.data.roomId) bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.ocs.data.roomId)
if (conversationUser != null) { if (conversationUser != null) {
if (conversationUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable( bundle.putParcelable(
BundleKeys.KEY_ACTIVE_CONVERSATION, BundleKeys.KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.ocs.data) Parcels.wrap(roomOverall.ocs.data)
@ -1788,7 +1787,6 @@ class ChatController(args: Bundle) :
router, conversationUser.id, router, conversationUser.id,
roomOverall.ocs.data.token, bundle, false roomOverall.ocs.data.token, bundle, false
) )
}
} else { } else {
conversationIntent.putExtras(bundle) conversationIntent.putExtras(bundle)
startActivity(conversationIntent) startActivity(conversationIntent)

View File

@ -308,13 +308,11 @@ public class ContactsController extends BaseController implements SearchView.OnQ
@Override @Override
public void onNext(RoomOverall roomOverall) { public void onNext(RoomOverall roomOverall) {
Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), currentUser); bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(), currentUser);
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId());
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
// FIXME once APIv2 or later is used only, the createRoom already returns all the data // FIXME once APIv2 or later is used only, the createRoom already returns all the data
ncApi.getRoom(credentials, ncApi.getRoom(credentials,
ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(), ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(),
@ -347,18 +345,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ
} }
}); });
} else {
conversationIntent.putExtras(bundle);
startActivity(conversationIntent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!isDestroyed() && !isBeingDestroyed()) {
getRouter().popCurrentController();
}
}
}, 100);
}
} }
@Override @Override
@ -885,16 +871,11 @@ public class ContactsController extends BaseController implements SearchView.OnQ
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId());
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(),
Parcels.wrap(roomOverall.getOcs().getData())); Parcels.wrap(roomOverall.getOcs().getData()));
ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(), ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(),
roomOverall.getOcs().getData().getToken(), bundle, true); roomOverall.getOcs().getData().getToken(), bundle, true);
} else {
startActivity(conversationIntent);
new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);
}
} }
} }

View File

@ -736,17 +736,9 @@ public class ConversationsListController extends BaseController implements Searc
} else { } else {
currentUser = userUtils.getCurrentUser(); currentUser = userUtils.getCurrentUser();
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(conversation)); bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(conversation));
ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(), ConductorRemapping.INSTANCE.remapChatController(getRouter(), currentUser.getId(),
conversation.getToken(), bundle, false); conversation.getToken(), bundle, false);
} else {
overridePushHandler(new NoOpControllerChangeHandler());
overridePopHandler(new NoOpControllerChangeHandler());
Intent callIntent = new Intent(getActivity(), MagicCallActivity.class);
callIntent.putExtras(bundle);
startActivity(callIntent);
}
} }
} }

View File

@ -448,6 +448,8 @@ public class OperationsMenuController extends BaseController {
@Override @Override
public void onNext(CapabilitiesOverall capabilitiesOverall) { public void onNext(CapabilitiesOverall capabilitiesOverall) {
// Guest checking the capabilities so there is no global server EOL warning until here.
// FIXME check the serverEOL capabilities instead
if (capabilitiesOverall.getOcs().getData() if (capabilitiesOverall.getOcs().getData()
.getCapabilities().getSpreedCapability() != null && .getCapabilities().getSpreedCapability() != null &&
capabilitiesOverall.getOcs().getData() capabilitiesOverall.getOcs().getData()
@ -471,14 +473,6 @@ public class OperationsMenuController extends BaseController {
initiateConversation(false, capabilitiesOverall.getOcs().getData() initiateConversation(false, capabilitiesOverall.getOcs().getData()
.getCapabilities()); .getCapabilities());
} }
} 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 { } else {
showResultImage(false, true); showResultImage(false, true);
} }
@ -589,14 +583,10 @@ public class OperationsMenuController extends BaseController {
} }
}); });
} }
} else {
if (!currentUser.hasSpreedFeatureCapability("chat-v2")) {
showResultImage(true, false);
} else { } else {
initiateConversation(true, null); initiateConversation(true, null);
} }
} }
}
private void initiateConversation(boolean dismissView, @Nullable Capabilities capabilities) { private void initiateConversation(boolean dismissView, @Nullable Capabilities capabilities) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -605,6 +595,8 @@ public class OperationsMenuController extends BaseController {
if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) { if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
isGuestUser = true; isGuestUser = true;
// Guest checking the capabilities so there is no global server EOL warning until here.
// FIXME check the serverEOL capabilities instead
hasChatCapability = capabilities != null && capabilities.getSpreedCapability() != null && capabilities.getSpreedCapability().getFeatures() != null && capabilities.getSpreedCapability().getFeatures().contains("chat-v2"); hasChatCapability = capabilities != null && capabilities.getSpreedCapability() != null && capabilities.getSpreedCapability().getFeatures() != null && capabilities.getSpreedCapability().getFeatures().contains("chat-v2");
} else { } else {
hasChatCapability = currentUser.hasSpreedFeatureCapability("chat-v2"); hasChatCapability = currentUser.hasSpreedFeatureCapability("chat-v2");

View File

@ -598,9 +598,6 @@ public class NotificationWorker extends Worker {
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class); JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
boolean hasChatSupport = signatureVerification.getUserEntity().
hasSpreedFeatureCapability("chat-v2");
boolean shouldShowNotification = decryptedPushMessage.getApp().equals("spreed"); boolean shouldShowNotification = decryptedPushMessage.getApp().equals("spreed");
if (shouldShowNotification) { if (shouldShowNotification) {
@ -608,7 +605,7 @@ public class NotificationWorker extends Worker {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
boolean startACall = decryptedPushMessage.getType().equals("call") || !hasChatSupport; boolean startACall = decryptedPushMessage.getType().equals("call");
if (startACall) { if (startACall) {
intent = new Intent(context, MagicCallActivity.class); intent = new Intent(context, MagicCallActivity.class);
} else { } else {