소스 검색

Inject api version in call api

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 4 년 전
부모
커밋
f0eb3fec37

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

@@ -302,9 +302,18 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
         var hasParticipantsInCall = false
         var inCallOnDifferentDevice = false
 
+
+        val apiVersion = ApiUtils.getApiVersion(signatureVerification.userEntity, "conversation", 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(
+                apiVersion,
                 signatureVerification.userEntity.baseUrl,
                 decryptedPushMessage.id
             )
@@ -347,4 +356,10 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
                 }
             })
     }
+
+    companion object {
+
+        private val TAG = "MagicFirebaseMessagingService"
+        private const val ID_DELETE_CONVERSATION_DIALOG = 0
+    }
 }

+ 24 - 4
app/src/main/java/com/nextcloud/talk/controllers/CallController.java

@@ -1302,8 +1302,14 @@ public class CallController extends BaseController {
             inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue();
         }
 
-        ncApi.joinCall(credentials,
-                       ApiUtils.getUrlForCall(baseUrl, roomToken), inCallFlag)
+        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.joinCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken), inCallFlag)
                 .subscribeOn(Schedulers.io())
                 .retry(3)
                 .observeOn(AndroidSchedulers.mainThread())
@@ -1627,7 +1633,14 @@ public class CallController extends BaseController {
     }
 
     private void hangupNetworkCalls(boolean shutDownView) {
-        ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(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.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken))
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Observer<GenericOverall>() {
@@ -1762,7 +1775,14 @@ public class CallController extends BaseController {
 
     private void getPeersForCall() {
         Log.d(TAG, "getPeersForCall");
-        ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(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.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken))
                 .subscribeOn(Schedulers.io())
                 .subscribe(new Observer<ParticipantsOverall>() {
                     @Override

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

@@ -208,8 +208,16 @@ public class CallNotificationController extends BaseController {
                                                  .pushChangeHandler(new HorizontalChangeHandler()));
     }
 
+    @SuppressLint("LongLogTag")
     private void checkIfAnyParticipantsRemainInRoom() {
-        ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(userBeingCalled.getBaseUrl(),
+        Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {1});
+
+        if (apiVersion == null) {
+            Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
+            return;
+        }
+
+        ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(apiVersion, userBeingCalled.getBaseUrl(),
                                                                   currentConversation.getToken()))
                 .subscribeOn(Schedulers.io())
                 .takeWhile(observable -> !leavingScreen)

+ 9 - 8
app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java

@@ -196,6 +196,10 @@ public class ApiUtils {
         return getUrlForRoom(version, baseUrl, token) + "/webinary/lobby";
     }
 
+    public static String getUrlForCall(int version, String baseUrl, String token) {
+        return getUrlForApi(version, baseUrl) + "/call/" + token;
+    }
+
     public static RetrofitBucket getRetrofitBucketForCreateRoom(int version, String baseUrl, String roomType,
                                                                 @Nullable String invite,
                                                                 @Nullable String conversationName) {
@@ -243,15 +247,12 @@ public class ApiUtils {
         return retrofitBucket;
     }
 
-    public static String getUrlForCall(String baseUrl, String token) {
-        // FIXME Introduce API version
-        return baseUrl + ocsApiVersion + spreedApiVersion + "/call/" + token;
-
-    }
-
+    /**
+     * @deprecated Method is only needed before Talk 4 which is from 2018 => todrop
+     */
+    @Deprecated
     public static String getUrlForCallPing(String baseUrl, String token) {
-        // FIXME Introduce API version
-        return getUrlForCall(baseUrl, token) + "/ping";
+        return getUrlForCall(1, baseUrl, token) + "/ping";
     }
 
     public static String getUrlForChat(String baseUrl, String token) {