浏览代码

Change version to be specific to conversations api

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 4 年之前
父节点
当前提交
529541d896

+ 1 - 1
app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt

@@ -303,7 +303,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
         var inCallOnDifferentDevice = false
 
 
-        val apiVersion = ApiUtils.getApiVersion(signatureVerification.userEntity, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(signatureVerification.userEntity, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")

+ 2 - 2
app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt

@@ -231,7 +231,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
         val roomType = "1"
         val currentUser = userUtils.currentUser ?: return
 
-        val apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")
@@ -258,7 +258,7 @@ 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.getApiVersion(currentUser, "conversation", intArrayOf(1))
+                        val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(1))
 
                         if (apiVersion == null) {
                             Log.e(TAG, "No supported API version found")

+ 6 - 8
app/src/main/java/com/nextcloud/talk/controllers/CallController.java

@@ -441,7 +441,7 @@ public class CallController extends BaseController {
     }
 
     private void handleFromNotification() {
-        Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1});
+        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"));
@@ -1248,8 +1248,7 @@ public class CallController extends BaseController {
     private void joinRoomAndCall() {
         callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession();
 
-        Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation",
-                                                    new int[] {1});
+        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;
@@ -1309,7 +1308,7 @@ public class CallController extends BaseController {
             inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue();
         }
 
-        Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1});
+        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"));
@@ -1648,7 +1647,7 @@ public class CallController extends BaseController {
     }
 
     private void hangupNetworkCalls(boolean shutDownView) {
-        Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1});
+        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"));
@@ -1690,8 +1689,7 @@ public class CallController extends BaseController {
     }
 
     private void leaveRoom(boolean shutDownView) {
-        Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation",
-                                                    new int[] {1});
+        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;
@@ -1790,7 +1788,7 @@ public class CallController extends BaseController {
 
     private void getPeersForCall() {
         Log.d(TAG, "getPeersForCall");
-        Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1});
+        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"));

+ 2 - 2
app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java

@@ -210,7 +210,7 @@ public class CallNotificationController extends BaseController {
 
     @SuppressLint("LongLogTag")
     private void checkIfAnyParticipantsRemainInRoom() {
-        Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {1});
+        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"));
@@ -267,7 +267,7 @@ public class CallNotificationController extends BaseController {
 
     @SuppressLint("LongLogTag")
     private void handleFromNotification() {
-        Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {4, 3, 1});
+        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;

+ 5 - 5
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -294,7 +294,7 @@ class ChatController(args: Bundle) :
         }
 
         if (conversationUser != null) {
-            val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+            val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
             if (apiVersion == null) {
                 Log.e(TAG, "No supported API version found")
@@ -344,7 +344,7 @@ class ChatController(args: Bundle) :
             return
         }
 
-        val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")
@@ -977,7 +977,7 @@ class ChatController(args: Bundle) :
         if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) ||
             currentConversation?.sessionId == "0"
         ) {
-            val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+            val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
             if (apiVersion == null) {
                 Log.e(TAG, "No supported API version found")
@@ -1051,7 +1051,7 @@ class ChatController(args: Bundle) :
     }
 
     private fun leaveRoom() {
-        val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")
@@ -1806,7 +1806,7 @@ class ChatController(args: Bundle) :
             currentConversation?.name != userMentionClickEvent.userId
         ) {
 
-            val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+            val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
             if (apiVersion == null) {
                 Log.e(TAG, "No supported API version found")

+ 3 - 4
app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java

@@ -288,7 +288,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
                     userId = selectedUserIds.iterator().next();
                 }
 
-                Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1});
+                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"));
@@ -318,8 +318,7 @@ 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.getApiVersion(currentUser, "conversation",
-                                                                           new int[] {1});
+                                Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
                                 if (apiVersion != null && currentUser.hasSpreedFeatureCapability("chat-v2")) {
 
                                     ncApi.getRoom(credentials,
@@ -861,7 +860,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
                     roomType = "2";
                 }
 
-                Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1});
+                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"));

+ 4 - 4
app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt

@@ -310,7 +310,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
                 ).isChecked
         ) 1 else 0
 
-        val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")
@@ -449,7 +449,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
     }
 
     private fun getListOfParticipants() {
-        val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")
@@ -545,7 +545,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
     }
 
     private fun fetchRoomInfo() {
-        val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
         if (apiVersion == null) {
             Log.e(TAG, "No supported API version found")
@@ -726,7 +726,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
                     title(text = participant.displayName)
                     listItemsWithImage(items = items) { dialog, index, _ ->
 
-                        val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1))
+                        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
 
                         if (apiVersion == null) {
                             Log.e(TAG, "No supported API version found")

+ 1 - 1
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -418,7 +418,7 @@ public class ConversationsListController extends BaseController implements Searc
 
         callItems = new ArrayList<>();
 
-        Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {4, 1});
+        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;

+ 3 - 5
app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java

@@ -193,8 +193,7 @@ public class OperationsMenuController extends BaseController {
                 credentials = null;
             }
 
-            Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation",
-                                                        new int[] {1});
+            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"));
@@ -402,8 +401,7 @@ public class OperationsMenuController extends BaseController {
     @SuppressLint("LongLogTag")
     private void performGroupCallWorkaround(String credentials) {
 
-        Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation",
-                                                    new int[] {1});
+        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"));
@@ -567,7 +565,7 @@ public class OperationsMenuController extends BaseController {
             localInvitedGroups.remove(0);
         }
 
-        Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1});
+        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"));

+ 1 - 1
app/src/main/java/com/nextcloud/talk/jobs/AddParticipantsToConversation.java

@@ -70,7 +70,7 @@ public class AddParticipantsToConversation extends Worker {
     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});
+        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"));

+ 1 - 2
app/src/main/java/com/nextcloud/talk/jobs/DeleteConversationWorker.java

@@ -80,8 +80,7 @@ public class DeleteConversationWorker extends Worker {
         UserEntity operationUser = userUtils.getUserWithId(operationUserId);
 
         if (operationUser != null) {
-            Integer apiVersion = ApiUtils.getApiVersion(operationUser, "conversation",
-                                                        new int[] {1});
+            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"));

+ 1 - 2
app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.java

@@ -87,8 +87,7 @@ public class LeaveConversationWorker extends Worker {
             EventStatus eventStatus = new EventStatus(operationUser.getId(),
                     EventStatus.EventType.CONVERSATION_UPDATE, true);
 
-            Integer apiVersion = ApiUtils.getApiVersion(operationUser, "conversation",
-                                                        new int[] {1});
+            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"));

+ 1 - 2
app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java

@@ -152,8 +152,7 @@ public class NotificationWorker extends Worker {
             importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
         }
 
-        Integer apiVersion = ApiUtils.getApiVersion(userEntity, "conversation",
-                                                    new int[] {1});
+        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"));

+ 14 - 16
app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java

@@ -109,30 +109,28 @@ public class ApiUtils {
         return baseUrl + ocsApiVersion + "/cloud/capabilities";
     }
 
-    public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) {
-         if (apiName.equals("conversation")) {
-             boolean hasApiV4 = false;
-             for (int version : versions) {
-                 hasApiV4 |= version == 4;
-             }
-
-             if (!hasApiV4) {
-                 Exception e = new Exception("Api call did not try conversation-v4 api");
-                 Log.d(TAG, e.getMessage(), e);
-             }
-         }
+    public static Integer getConversationApiVersion(UserEntity capabilities, int[] versions) {
+        boolean hasApiV4 = false;
+        for (int version : versions) {
+            hasApiV4 |= version == 4;
+        }
+
+        if (!hasApiV4) {
+            Exception e = new Exception("Api call did not try conversation-v4 api");
+            Log.d(TAG, e.getMessage(), e);
+        }
 
         for (int version : versions) {
-            if (capabilities.hasSpreedFeatureCapability(apiName + "-v" + version)) {
+            if (capabilities.hasSpreedFeatureCapability("conversation-v" + version)) {
                 return version;
             }
 
             // Fallback for old API versions
-            if (apiName.equals("conversation") && (version == 1 || version == 2)) {
-                if (capabilities.hasSpreedFeatureCapability(apiName + "-v2")) {
+            if ((version == 1 || version == 2)) {
+                if (capabilities.hasSpreedFeatureCapability("conversation-v2")) {
                     return version;
                 }
-                if (version == 1  && capabilities.hasSpreedFeatureCapability(apiName)) {
+                if (version == 1  && capabilities.hasSpreedFeatureCapability("conversation")) {
                     return version;
                 }
             }

+ 1 - 1
app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java

@@ -97,7 +97,7 @@ public class DatabaseStorageModule implements StorageModule {
                             intValue = 0;
                     }
 
-                    Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {4, 1});
+                    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"));
                     }