From ee3dc43530de90f1045c3788a8b37780858e0216 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 4 May 2021 14:05:00 +0200 Subject: [PATCH] Throw the exception up Signed-off-by: Joas Schilling --- .../firebase/MagicFirebaseMessagingService.kt | 5 -- .../nextcloud/talk/activities/MainActivity.kt | 13 ---- .../talk/controllers/CallController.java | 61 +++---------------- .../CallNotificationController.java | 13 +--- .../talk/controllers/ChatController.kt | 44 +------------ .../talk/controllers/ContactsController.java | 19 ++---- .../controllers/ConversationInfoController.kt | 19 ------ .../ConversationsListController.java | 7 +-- .../bottomsheet/OperationsMenuController.java | 21 +------ .../jobs/AddParticipantsToConversation.java | 7 +-- .../talk/jobs/DeleteConversationWorker.java | 7 +-- .../talk/jobs/LeaveConversationWorker.java | 7 +-- .../talk/jobs/NotificationWorker.java | 8 +-- .../talk/jobs/SignalingSettingsWorker.java | 7 +-- .../MentionAutocompletePresenter.java | 7 +-- .../com/nextcloud/talk/utils/ApiUtils.java | 12 ++-- .../talk/utils/NoSupportedApiException.kt | 3 + .../DatabaseStorageModule.java | 5 +- .../webrtc/WebSocketConnectionHelper.java | 7 +-- 19 files changed, 38 insertions(+), 234 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/utils/NoSupportedApiException.kt diff --git a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt index 428553e7a..e77ab4ffb 100644 --- a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt +++ b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt @@ -305,11 +305,6 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { val apiVersion = ApiUtils.getConversationApiVersion(signatureVerification.userEntity, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi.getPeersForCall( ApiUtils.getCredentials(signatureVerification.userEntity.username, signatureVerification.userEntity.token), ApiUtils.getUrlForCall( 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 afccdd979..b0669d7b7 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt @@ -231,12 +231,6 @@ class MainActivity : BaseActivity(), ActionBarProvider { val currentUser = userUtils.currentUser ?: return val apiVersion = ApiUtils.getConversationApiVersion(currentUser, 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( apiVersion, currentUser.baseUrl, roomType, @@ -257,13 +251,6 @@ class MainActivity : BaseActivity(), ActionBarProvider { bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs.data.token) bundle.putString(KEY_ROOM_ID, roomOverall.ocs.data.roomId) if (currentUser.hasSpreedFeatureCapability("chat-v2")) { - val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(1)) - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi.getRoom( credentials, ApiUtils.getUrlForRoom( 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 5695c98c0..7dc788631 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -441,12 +441,7 @@ public class CallController extends BaseController { } private void handleFromNotification() { - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, baseUrl)) .retry(3) @@ -1104,12 +1099,7 @@ public class CallController extends BaseController { } private void fetchSignalingSettings() { - Integer apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[] {2, 1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[] {2, 1}); ncApi.getSignalingSettings(credentials, ApiUtils.getUrlForSignalingSettings(apiVersion, baseUrl)) .subscribeOn(Schedulers.io()) @@ -1248,11 +1238,7 @@ public class CallController extends BaseController { private void joinRoomAndCall() { callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession(); - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); if (TextUtils.isEmpty(callSession)) { ncApi.joinRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken), @@ -1308,12 +1294,7 @@ public class CallController extends BaseController { inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue(); } - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); ncApi.joinCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken), inCallFlag) .subscribeOn(Schedulers.io()) @@ -1375,12 +1356,7 @@ public class CallController extends BaseController { } if (!hasExternalSignalingServer) { - Integer apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[] {2, 1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[] {2, 1}); ncApi.pullSignalingMessages(credentials, ApiUtils.getUrlForSignaling(apiVersion, baseUrl, urlToken)) @@ -1647,12 +1623,7 @@ public class CallController extends BaseController { } private void hangupNetworkCalls(boolean shutDownView) { - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken)) .subscribeOn(Schedulers.io()) @@ -1689,11 +1660,7 @@ public class CallController extends BaseController { } private void leaveRoom(boolean shutDownView) { - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); ncApi.leaveRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken)) .subscribeOn(Schedulers.io()) @@ -1788,12 +1755,7 @@ public class CallController extends BaseController { private void getPeersForCall() { Log.d(TAG, "getPeersForCall"); - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1}); ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken)) .subscribeOn(Schedulers.io()) @@ -2099,12 +2061,7 @@ public class CallController extends BaseController { urlToken = roomToken; } - Integer apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[] {2, 1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[] {2, 1}); ncApi.sendSignalingMessages(credentials, ApiUtils.getUrlForSignaling(apiVersion, baseUrl, urlToken), strings.toString()) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java index a53e35732..f537c8531 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java @@ -210,12 +210,7 @@ public class CallNotificationController extends BaseController { @SuppressLint("LongLogTag") private void checkIfAnyParticipantsRemainInRoom() { - Integer apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {1}); ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, userBeingCalled.getBaseUrl(), currentConversation.getToken())) @@ -267,11 +262,7 @@ public class CallNotificationController extends BaseController { @SuppressLint("LongLogTag") private void handleFromNotification() { - Integer apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {4, 3, 1}); - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {4, 3, 1}); ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userBeingCalled.getBaseUrl(), roomId)) .subscribeOn(Schedulers.io()) 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 8dee9c60a..23ef78133 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -82,7 +82,6 @@ import com.facebook.imagepipeline.image.CloseableImage import com.google.android.flexbox.FlexboxLayout import com.nextcloud.talk.R import com.nextcloud.talk.activities.MagicCallActivity -import com.nextcloud.talk.activities.MainActivity import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder @@ -116,6 +115,7 @@ import com.nextcloud.talk.utils.DateUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.KeyboardUtils import com.nextcloud.talk.utils.MagicCharPolicy +import com.nextcloud.talk.utils.NoSupportedApiException import com.nextcloud.talk.utils.NotificationUtils import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.bundle.BundleKeys @@ -296,11 +296,6 @@ class ChatController(args: Bundle) : if (conversationUser != null) { val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi?.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser.baseUrl, roomToken)) ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) @@ -346,11 +341,6 @@ class ChatController(args: Bundle) : val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi?.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, conversationUser?.baseUrl)) ?.subscribeOn(Schedulers.io())?.observeOn(AndroidSchedulers.mainThread()) ?.subscribe(object : Observer { @@ -979,11 +969,6 @@ class ChatController(args: Bundle) : ) { val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi?.joinRoom( credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, conversationUser?.baseUrl, roomToken), @@ -1053,11 +1038,6 @@ class ChatController(args: Bundle) : private fun leaveRoom() { val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi?.leaveRoom( credentials, ApiUtils.getUrlForParticipantsActive( @@ -1144,11 +1124,6 @@ class ChatController(args: Bundle) : if (conversationUser != null) { val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi!!.sendChatMessage( credentials, ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl, roomToken), @@ -1251,16 +1226,11 @@ class ChatController(args: Bundle) : } if (!wasDetached) { - var apiVersion: Int? + var apiVersion: Int // FIXME this is a best guess, guests would need to get the capabilities themselves apiVersion = 1 if (conversationUser != null) { apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1)) - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } } if (lookIntoFuture > 0) { @@ -1687,11 +1657,6 @@ class ChatController(args: Bundle) : } R.id.action_delete_message -> { val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1)) - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - } - ncApi?.deleteChatMessage( credentials, ApiUtils.getUrlForChatMessage(apiVersion, conversationUser?.baseUrl, roomToken, @@ -1807,11 +1772,6 @@ class ChatController(args: Bundle) : val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom( 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 a0e9ec15f..8cde43f6e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -288,13 +288,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ userId = selectedUserIds.iterator().next(); } - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } - + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, currentUser.getBaseUrl(), roomType, @@ -318,8 +312,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); - if (apiVersion != null && currentUser.hasSpreedFeatureCapability("chat-v2")) { + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); + if (currentUser.hasSpreedFeatureCapability("chat-v2")) { ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(), @@ -860,12 +854,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ roomType = "2"; } - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return false; - } + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion, currentUser.getBaseUrl(), diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt index 83518b3e1..8ebe51416 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt @@ -312,11 +312,6 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi.setLobbyForConversation( ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token), ApiUtils.getUrlForRoomWebinaryLobby(apiVersion, conversationUser.baseUrl, conversation!!.token), @@ -452,11 +447,6 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA private fun getListOfParticipants() { val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi.getPeersForCall( credentials, ApiUtils.getUrlForParticipants(apiVersion, conversationUser!!.baseUrl, conversationToken) @@ -549,11 +539,6 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA private fun fetchRoomInfo() { val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - return - } - ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser!!.baseUrl, conversationToken)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -731,10 +716,6 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1)) - if (apiVersion == null) { - Log.e(TAG, "No supported API version found") - } - if (index == 0) { if (participant.type == Participant.ParticipantType.MODERATOR) { ncApi.demoteModeratorToUser( diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java index 090382152..0fff10672 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -418,12 +418,7 @@ public class ConversationsListController extends BaseController implements Searc callItems = new ArrayList<>(); - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {4, 1}); - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } - + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {4, 1}); roomsQueryDisposable = ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, currentUser.getBaseUrl())) 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 9482d0f7d..5c16c3e38 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 @@ -193,12 +193,7 @@ public class OperationsMenuController extends BaseController { credentials = null; } - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); switch (operationCode) { case 2: @@ -401,12 +396,7 @@ public class OperationsMenuController extends BaseController { @SuppressLint("LongLogTag") private void performGroupCallWorkaround(String credentials) { - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomPublic(apiVersion, currentUser.getBaseUrl(), conversation.getToken())) @@ -565,12 +555,7 @@ public class OperationsMenuController extends BaseController { localInvitedGroups.remove(0); } - Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1}); if (localInvitedUsers.size() > 0 || (localInvitedGroups.size() > 0 && currentUser.hasSpreedFeatureCapability("invite-groups-and-mails"))) { if ((localInvitedGroups.size() > 0 && currentUser.hasSpreedFeatureCapability("invite-groups-and-mails"))) { 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 c65aa9bc5..09039daa3 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java @@ -73,12 +73,7 @@ public class AddParticipantsToConversation extends Worker { String[] selectedGroupIds = data.getStringArray(BundleKeys.INSTANCE.getKEY_SELECTED_GROUPS()); UserEntity user = userUtils.getUserWithInternalId(data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1)); - Integer apiVersion = ApiUtils.getConversationApiVersion(user, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return Result.failure(); - } + int apiVersion = ApiUtils.getConversationApiVersion(user, new int[] {1}); String conversationToken = data.getString(BundleKeys.INSTANCE.getKEY_TOKEN()); String credentials = ApiUtils.getCredentials(user.getUsername(), user.getToken()); diff --git a/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java index dccb8c1be..2b94215b1 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java @@ -80,12 +80,7 @@ public class DeleteConversationWorker extends Worker { UserEntity operationUser = userUtils.getUserWithId(operationUserId); if (operationUser != null) { - Integer apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return Result.failure(); - } + int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1}); String credentials = ApiUtils.getCredentials(operationUser.getUsername(), operationUser.getToken()); ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new 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 8a6a72c8b..b2d52ea33 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java @@ -87,12 +87,7 @@ public class LeaveConversationWorker extends Worker { EventStatus eventStatus = new EventStatus(operationUser.getId(), EventStatus.EventType.CONVERSATION_UPDATE, true); - Integer apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return Result.failure(); - } + int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1}); ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForParticipantsSelf(apiVersion, operationUser.getBaseUrl(), diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java index 7aec9e32c..ad5f09d2e 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -152,13 +152,7 @@ public class NotificationWorker extends Worker { importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue()); } - Integer apiVersion = ApiUtils.getConversationApiVersion(userEntity, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } - + int apiVersion = ApiUtils.getConversationApiVersion(userEntity, new int[] {1}); ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userEntity.getBaseUrl(), intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) diff --git a/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java index a4a1be146..7d640dbc1 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/SignalingSettingsWorker.java @@ -82,12 +82,7 @@ public class SignalingSettingsWorker extends Worker { userEntity = userEntityList.get(i); UserEntity finalUserEntity = userEntity; - Integer apiVersion = ApiUtils.getSignalingApiVersion(finalUserEntity, new int[] {2, 1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - continue; - } + int apiVersion = ApiUtils.getSignalingApiVersion(finalUserEntity, new int[] {2, 1}); ncApi.getSignalingSettings(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForSignalingSettings(apiVersion, userEntity.getBaseUrl())) diff --git a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java index 1662d5d49..501fbedba 100644 --- a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java +++ b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java @@ -95,12 +95,7 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter queryString = ""; } - Integer apiVersion = ApiUtils.getChatApiVersion(currentUser, new int[] {1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return; - } + int apiVersion = ApiUtils.getChatApiVersion(currentUser, new int[] {1}); adapter.setFilter(queryString); ncApi.getMentionAutocompleteSuggestions( 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 d8fd6f660..40a50f07e 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -109,7 +109,7 @@ public class ApiUtils { return baseUrl + ocsApiVersion + "/cloud/capabilities"; } - public static Integer getConversationApiVersion(UserEntity capabilities, int[] versions) { + public static int getConversationApiVersion(UserEntity capabilities, int[] versions) throws NoSupportedApiException { boolean hasApiV4 = false; for (int version : versions) { hasApiV4 |= version == 4; @@ -135,10 +135,10 @@ public class ApiUtils { } } } - return null; + throw new NoSupportedApiException(); } - public static Integer getSignalingApiVersion(UserEntity capabilities, int[] versions) { + public static int getSignalingApiVersion(UserEntity capabilities, int[] versions) throws NoSupportedApiException { for (int version : versions) { if (version == 2 && capabilities.hasSpreedFeatureCapability("sip-support")) { return version; @@ -149,17 +149,17 @@ public class ApiUtils { return version; } } - return null; + throw new NoSupportedApiException(); } - public static Integer getChatApiVersion(UserEntity capabilities, int[] versions) { + public static int getChatApiVersion(UserEntity capabilities, int[] versions) throws NoSupportedApiException { for (int version : versions) { if (version == 1 && capabilities.hasSpreedFeatureCapability("chat-v2")) { // Do not question that chat-v2 capability shows the availability of api/v1/ endpoint *see no evil* return version; } } - return null; + throw new NoSupportedApiException(); } protected static String getUrlForApi(int version, String baseUrl) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/NoSupportedApiException.kt b/app/src/main/java/com/nextcloud/talk/utils/NoSupportedApiException.kt new file mode 100644 index 000000000..53cdd2076 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/NoSupportedApiException.kt @@ -0,0 +1,3 @@ +package com.nextcloud.talk.utils + +class NoSupportedApiException : RuntimeException("No supported API version found") \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java index 65fa295a8..a1847836c 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java @@ -97,10 +97,7 @@ public class DatabaseStorageModule implements StorageModule { intValue = 0; } - Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {4, 1}); - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - } + int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {4, 1}); ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()), ApiUtils.getUrlForRoomNotificationLevel(apiVersion, conversationUser.getBaseUrl(), diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java index b26deab5e..e35c6f267 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java @@ -94,12 +94,7 @@ public class WebSocketConnectionHelper { @SuppressLint("LongLogTag") HelloOverallWebSocketMessage getAssembledHelloModel(UserEntity userEntity, String ticket) { - Integer apiVersion = ApiUtils.getSignalingApiVersion(userEntity, new int[] {2, 1}); - - if (apiVersion == null) { - Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); - return null; - } + int apiVersion = ApiUtils.getSignalingApiVersion(userEntity, new int[] {2, 1}); HelloOverallWebSocketMessage helloOverallWebSocketMessage = new HelloOverallWebSocketMessage(); helloOverallWebSocketMessage.setType("hello");