瀏覽代碼

Fix capability checking when there could be no user

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 4 年之前
父節點
當前提交
9f0c760c49

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

@@ -334,7 +334,11 @@ class ChatController(args: Bundle) :
     }
 
     private fun handleFromNotification() {
-        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        var apiVersion = 1
+        // FIXME Can this be called for guests?
+        if (conversationUser != null) {
+            apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        }
 
         ncApi?.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, conversationUser?.baseUrl))
             ?.subscribeOn(Schedulers.io())?.observeOn(AndroidSchedulers.mainThread())
@@ -962,7 +966,11 @@ class ChatController(args: Bundle) :
         if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) ||
             currentConversation?.sessionId == "0"
         ) {
-            val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+            var apiVersion = 1
+            // FIXME Fix API checking with guests?
+            if (conversationUser != null) {
+                apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+            }
 
             ncApi?.joinRoom(
                 credentials,
@@ -1031,7 +1039,11 @@ class ChatController(args: Bundle) :
     }
 
     private fun leaveRoom() {
-        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        var apiVersion = 1
+        // FIXME Fix API checking with guests?
+        if (conversationUser != null) {
+            apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        }
 
         ncApi?.leaveRoom(
             credentials,
@@ -1221,9 +1233,8 @@ class ChatController(args: Bundle) :
         }
 
         if (!wasDetached) {
-            var apiVersion: Int
+            var apiVersion = 1
             // 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))
             }
@@ -1651,7 +1662,12 @@ class ChatController(args: Bundle) :
                         true
                     }
                     R.id.action_delete_message -> {
-                        val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
+                        var apiVersion = 1
+                        // FIXME Fix API checking with guests?
+                        if (conversationUser != null) {
+                            apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+                        }
+
                         ncApi?.deleteChatMessage(
                             credentials,
                             ApiUtils.getUrlForChatMessage(
@@ -1769,7 +1785,11 @@ class ChatController(args: Bundle) :
             currentConversation?.name != userMentionClickEvent.userId
         ) {
 
-            val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+            var apiVersion = 1
+            // FIXME Fix API checking with guests?
+            if (conversationUser != null) {
+                apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+            }
 
             val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
                 apiVersion, conversationUser?.baseUrl, "1",

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

@@ -312,9 +312,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());
 
-                                int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
                                 if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
-
                                     ncApi.getRoom(credentials,
                                             ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(),
                                                     roomOverall.getOcs().getData().getToken()))

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

@@ -441,7 +441,11 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
     }
 
     private fun getListOfParticipants() {
-        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        var apiVersion = 1
+        // FIXME Fix API checking with guests?
+        if (conversationUser != null) {
+            apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        }
 
         ncApi.getPeersForCall(
             credentials,
@@ -532,7 +536,11 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
     }
 
     private fun fetchRoomInfo() {
-        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        var apiVersion = 1
+        // FIXME Fix API checking with guests?
+        if (conversationUser != null) {
+            apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
+        }
 
         ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser!!.baseUrl, conversationToken))
             .subscribeOn(Schedulers.io())

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

@@ -185,11 +185,15 @@ public class OperationsMenuController extends BaseController {
         if (currentUser != null) {
             credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
 
+            int apiVersion;
             if (!TextUtils.isEmpty(baseUrl) && !baseUrl.equals(currentUser.getBaseUrl())) {
                 credentials = null;
+                // FIXME joining a public link we need to check other capabilities
+                apiVersion = 1;
+            } else {
+                apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
             }
 
-            int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
 
             switch (operationCode) {
                 case 2: