diff --git a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt index a6ca9b1d3..4608b09c7 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt @@ -231,9 +231,16 @@ class MainActivity : BaseActivity(), ActionBarProvider { val roomType = "1" val currentUser = userUtils.currentUser ?: return + val apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token) val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom( - currentUser.baseUrl, roomType, + apiVersion, currentUser.baseUrl, roomType, userId, null ) ncApi.createRoom( diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java index 21416baca..80365056d 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -441,7 +441,14 @@ public class CallController extends BaseController { } private void handleFromNotification() { - ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(baseUrl)) + Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1}); + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return; + } + + ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, baseUrl)) .retry(3) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -1234,9 +1241,16 @@ public class CallController extends BaseController { private void joinRoomAndCall() { callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession(); + Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", + new int[] {1}); + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return; + } + if (TextUtils.isEmpty(callSession)) { - ncApi.joinRoom(credentials, ApiUtils.getUrlForSettingMyselfAsActiveParticipant(baseUrl, - roomToken), conversationPassword) + ncApi.joinRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken), + conversationPassword) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .retry(3) @@ -1648,7 +1662,14 @@ public class CallController extends BaseController { } private void leaveRoom(boolean shutDownView) { - ncApi.leaveRoom(credentials, ApiUtils.getUrlForSettingMyselfAsActiveParticipant(baseUrl, roomToken)) + Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", + new int[] {1}); + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return; + } + + ncApi.leaveRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer() { diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index af8292652..df3f53d2b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -977,9 +977,17 @@ class ChatController(args: Bundle) : if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) || currentConversation?.sessionId == "0" ) { + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + ncApi?.joinRoom( credentials, - ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser?.baseUrl, roomToken), roomPassword + ApiUtils.getUrlForParticipantsActive(apiVersion, conversationUser?.baseUrl, roomToken), + roomPassword ) ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) @@ -1043,9 +1051,17 @@ class ChatController(args: Bundle) : } private fun leaveRoom() { + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + ncApi?.leaveRoom( credentials, - ApiUtils.getUrlForSettingMyselfAsActiveParticipant( + ApiUtils.getUrlForParticipantsActive( + apiVersion, conversationUser?.baseUrl, roomToken ) @@ -1762,8 +1778,16 @@ class ChatController(args: Bundle) : if (currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL || currentConversation?.name != userMentionClickEvent.userId ) { + + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom( - conversationUser?.baseUrl, "1", + apiVersion, conversationUser?.baseUrl, "1", userMentionClickEvent.userId, null ) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index 9366590b2..9026f0cd6 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -288,8 +288,18 @@ public class ContactsController extends BaseController implements SearchView.OnQ userId = selectedUserIds.iterator().next(); } - RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(), roomType, - userId, null); + Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return; + } + + RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, + currentUser.getBaseUrl(), + roomType, + userId, + null); ncApi.createRoom(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) .subscribeOn(Schedulers.io()) @@ -851,7 +861,18 @@ public class ContactsController extends BaseController implements SearchView.OnQ roomType = "2"; } - RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(), roomType, userItem.getModel().getUserId(), null); + Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return false; + } + + RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, + currentUser.getBaseUrl(), + roomType, + userItem.getModel().getUserId(), + null); ncApi.createRoom(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) 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 afaa92c72..9208daa88 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 @@ -196,7 +196,7 @@ public class OperationsMenuController extends BaseController { Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); - if(apiVersion == null) { + if (apiVersion == null) { Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); return; } @@ -285,7 +285,7 @@ public class OperationsMenuController extends BaseController { if (conversationType.equals(Conversation.ConversationType.ROOM_PUBLIC_CALL) || !currentUser.hasSpreedFeatureCapability("empty-group-room")) { - retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(), + retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, currentUser.getBaseUrl(), "3", invite, conversationName); } else { String roomType = "2"; @@ -294,7 +294,7 @@ public class OperationsMenuController extends BaseController { roomType = "3"; } - retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(), + retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, currentUser.getBaseUrl(), roomType, invite, conversationName); } @@ -405,7 +405,7 @@ public class OperationsMenuController extends BaseController { Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); - if(apiVersion == null) { + if (apiVersion == null) { Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); return; } @@ -558,6 +558,7 @@ public class OperationsMenuController extends BaseController { }); } + @SuppressLint("LongLogTag") private void inviteUsersToAConversation() { RetrofitBucket retrofitBucket; final ArrayList localInvitedUsers = invitedUsers; @@ -566,11 +567,20 @@ public class OperationsMenuController extends BaseController { localInvitedGroups.remove(0); } + Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return; + } + if (localInvitedUsers.size() > 0 || (localInvitedGroups.size() > 0 && currentUser.hasSpreedFeatureCapability("invite-groups-and-mails"))) { if ((localInvitedGroups.size() > 0 && currentUser.hasSpreedFeatureCapability("invite-groups-and-mails"))) { for (int i = 0; i < localInvitedGroups.size(); i++) { final String groupId = localInvitedGroups.get(i); - retrofitBucket = ApiUtils.getRetrofitBucketForAddGroupParticipant(currentUser.getBaseUrl(), conversation.getToken(), + retrofitBucket = ApiUtils.getRetrofitBucketForAddGroupParticipant(apiVersion, + currentUser.getBaseUrl(), + conversation.getToken(), groupId); ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) @@ -610,8 +620,10 @@ public class OperationsMenuController extends BaseController { for (int i = 0; i < localInvitedUsers.size(); i++) { final String userId = invitedUsers.get(i); - retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(currentUser.getBaseUrl(), conversation.getToken(), - userId); + retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(apiVersion, + currentUser.getBaseUrl(), + conversation.getToken(), + userId); ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java b/app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java index cb2d8cb4d..5ad49209c 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java @@ -20,7 +20,9 @@ package com.nextcloud.talk.jobs; +import android.annotation.SuppressLint; import android.content.Context; +import android.util.Log; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; @@ -46,6 +48,8 @@ import io.reactivex.schedulers.Schedulers; @AutoInjector(NextcloudTalkApplication.class) public class AddParticipantsToConversation extends Worker { + private static final String TAG = "AddParticipantsToConversation"; + @Inject NcApi ncApi; @@ -60,19 +64,29 @@ public class AddParticipantsToConversation extends Worker { NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } + @SuppressLint("LongLogTag") @NonNull @Override public Result doWork() { + UserEntity user = userUtils.getUserWithInternalId(data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1)); + + Integer apiVersion = ApiUtils.getApiVersion(user, "conversation", new int[] {1}); + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); + return Result.failure(); + } + Data data = getInputData(); String[] selectedUserIds = data.getStringArray(BundleKeys.INSTANCE.getKEY_SELECTED_USERS()); String[] selectedGroupIds = data.getStringArray(BundleKeys.INSTANCE.getKEY_SELECTED_GROUPS()); - UserEntity user = userUtils.getUserWithInternalId(data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1)); String conversationToken = data.getString(BundleKeys.INSTANCE.getKEY_TOKEN()); String credentials = ApiUtils.getCredentials(user.getUsername(), user.getToken()); RetrofitBucket retrofitBucket; for (String userId : selectedUserIds) { - retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(user.getBaseUrl(), conversationToken, + retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(apiVersion, user.getBaseUrl(), + conversationToken, userId); ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) @@ -81,7 +95,7 @@ public class AddParticipantsToConversation extends Worker { } for (String groupId : selectedGroupIds) { - retrofitBucket = ApiUtils.getRetrofitBucketForAddGroupParticipant(user.getBaseUrl(), conversationToken, + retrofitBucket = ApiUtils.getRetrofitBucketForAddGroupParticipant(apiVersion, user.getBaseUrl(), conversationToken, groupId); ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) diff --git a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java index fd58d329b..69807d46d 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java @@ -90,7 +90,7 @@ public class LeaveConversationWorker extends Worker { Integer apiVersion = ApiUtils.getApiVersion(operationUser, "conversation", new int[] {1}); - if(apiVersion == null) { + if (apiVersion == null) { Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); return Result.failure(); } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 86701f3d6..efc9ad8ea 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -29,10 +29,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.models.RetrofitBucket; import com.nextcloud.talk.models.database.UserEntity; -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import androidx.annotation.DimenRes; @@ -41,18 +38,18 @@ import okhttp3.Credentials; public class ApiUtils { private static final String TAG = "ApiUtils"; - private static String ocsApiVersion = "/ocs/v2.php"; - private static String spreedApiVersion = "/apps/spreed/api/v1"; - private static String spreedApiBase = ocsApiVersion + "/apps/spreed/api/v"; + private static final String ocsApiVersion = "/ocs/v2.php"; + private static final String spreedApiVersion = "/apps/spreed/api/v1"; + private static final String spreedApiBase = ocsApiVersion + "/apps/spreed/api/v"; - private static String userAgent = "Mozilla/5.0 (Android) Nextcloud-Talk v"; + private static final String userAgent = "Mozilla/5.0 (Android) Nextcloud-Talk v"; public static String getUserAgent() { return userAgent + BuildConfig.VERSION_NAME; } /** - * @deprecated Please specify the api version you want to use via + * @deprecated This is only supported on API v1-3, in API v4+ please use * {@link ApiUtils#getUrlForAttendees(int, String, String)} instead. */ @Deprecated @@ -108,28 +105,10 @@ public class ApiUtils { return retrofitBucket; } - /** - * @deprecated Please specify the api version you want to use via - * {@link ApiUtils#getUrlForParticipantsActive(int, String, String)} instead. - */ - @Deprecated - public static String getUrlForSettingMyselfAsActiveParticipant(String baseUrl, String token) { - return getUrlForParticipantsActive(1, baseUrl, token); - } - public static String getUrlForCapabilities(String baseUrl) { return baseUrl + ocsApiVersion + "/cloud/capabilities"; } - /** - * @deprecated Please specify the api version you want to use via - * {@link ApiUtils#getUrlForRooms(int, String)} instead. - */ - @Deprecated - public static String getUrlForGetRooms(String baseUrl) { - return getUrlForRooms(1, baseUrl); - } - public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) { if (apiName.equals("conversation")) { boolean hasApiV4 = false; @@ -217,12 +196,11 @@ public class ApiUtils { return getUrlForRoom(version, baseUrl, token) + "/webinary/lobby"; } - @Deprecated - public static RetrofitBucket getRetrofitBucketForCreateRoom(String baseUrl, String roomType, + public static RetrofitBucket getRetrofitBucketForCreateRoom(int version, String baseUrl, String roomType, @Nullable String invite, @Nullable String conversationName) { RetrofitBucket retrofitBucket = new RetrofitBucket(); - retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room"); + retrofitBucket.setUrl(getUrlForRooms(version, baseUrl)); Map queryMap = new HashMap<>(); queryMap.put("roomType", roomType); @@ -239,10 +217,9 @@ public class ApiUtils { return retrofitBucket; } - @Deprecated - public static RetrofitBucket getRetrofitBucketForAddParticipant(String baseUrl, String token, String user) { + public static RetrofitBucket getRetrofitBucketForAddParticipant(int version, String baseUrl, String token, String user) { RetrofitBucket retrofitBucket = new RetrofitBucket(); - retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/participants"); + retrofitBucket.setUrl(getUrlForParticipants(version, baseUrl, token)); Map queryMap = new HashMap<>(); @@ -254,46 +231,46 @@ public class ApiUtils { } - public static RetrofitBucket getRetrofitBucketForAddGroupParticipant(String baseUrl, String token, String group) { - RetrofitBucket retrofitBucket = getRetrofitBucketForAddParticipant(baseUrl, token, group); + public static RetrofitBucket getRetrofitBucketForAddGroupParticipant(int version, String baseUrl, String token, String group) { + RetrofitBucket retrofitBucket = getRetrofitBucketForAddParticipant(version, baseUrl, token, group); retrofitBucket.getQueryMap().put("source", "groups"); return retrofitBucket; } - public static RetrofitBucket getRetrofitBucketForAddMailParticipant(String baseUrl, String token, String mail) { - RetrofitBucket retrofitBucket = getRetrofitBucketForAddParticipant(baseUrl, token, mail); + public static RetrofitBucket getRetrofitBucketForAddMailParticipant(int version, String baseUrl, String token, String mail) { + RetrofitBucket retrofitBucket = getRetrofitBucketForAddParticipant(version, baseUrl, token, mail); retrofitBucket.getQueryMap().put("source", "emails"); return retrofitBucket; } - @Deprecated public static String getUrlForCall(String baseUrl, String token) { - // FIXME user APIv4 + // FIXME Introduce API version return baseUrl + ocsApiVersion + spreedApiVersion + "/call/" + token; } - @Deprecated public static String getUrlForCallPing(String baseUrl, String token) { + // FIXME Introduce API version return getUrlForCall(baseUrl, token) + "/ping"; } public static String getUrlForChat(String baseUrl, String token) { + // FIXME Introduce API version return baseUrl + ocsApiVersion + spreedApiVersion + "/chat/" + token; } - @Deprecated public static String getUrlForExternalServerAuthBackend(String baseUrl) { + // FIXME Introduce API version return getUrlForSignaling(baseUrl, null) + "/backend"; } public static String getUrlForMentionSuggestions(String baseUrl, String token) { + // FIXME Introduce API version return getUrlForChat(baseUrl, token) + "/mentions"; } - @Deprecated public static String getUrlForSignaling(String baseUrl, @Nullable String token) { - // FIXME use APIv2 ? + // FIXME Introduce API version String signalingUrl = baseUrl + ocsApiVersion + spreedApiVersion + "/signaling"; if (token == null) { return signalingUrl; @@ -302,17 +279,8 @@ public class ApiUtils { } } - /** - * @deprecated Please specify the api version you want to use via - * {@link ApiUtils#getUrlForRoomModerators(int, String, String)} instead. - */ - @Deprecated - public static String getUrlForModerators(String baseUrl, String roomToken) { - return getUrlForRoomModerators(1, baseUrl, roomToken); - } - - @Deprecated public static String getUrlForSignalingSettings(String baseUrl) { + // FIXME Introduce API version return getUrlForSignaling(baseUrl, null) + "/settings"; } @@ -326,6 +294,7 @@ public class ApiUtils { } public static String getUrlForUserSettings(String baseUrl) { + // FIXME Introduce API version return baseUrl + ocsApiVersion + spreedApiVersion + "/settings/user"; }