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 897ebbb15..a6ca9b1d3 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt @@ -28,6 +28,7 @@ import android.os.Bundle import android.os.Handler import android.provider.ContactsContract import android.text.TextUtils +import android.util.Log import android.view.ViewGroup import androidx.annotation.RequiresApi import autodagger.AutoInjector @@ -48,6 +49,7 @@ import com.nextcloud.talk.R import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.controllers.CallNotificationController +import com.nextcloud.talk.controllers.ChatController import com.nextcloud.talk.controllers.ConversationsListController import com.nextcloud.talk.controllers.LockedController import com.nextcloud.talk.controllers.ServerSelectionController @@ -249,9 +251,17 @@ 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)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + ncApi.getRoom( credentials, - ApiUtils.getRoom( + ApiUtils.getUrlForRoom( + apiVersion, currentUser.baseUrl, roomOverall.ocs.data.token ) 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 ea65f469f..af8292652 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -82,6 +82,7 @@ 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 @@ -293,7 +294,14 @@ class ChatController(args: Bundle) : } if (conversationUser != null) { - ncApi?.getRoom(credentials, ApiUtils.getRoom(conversationUser.baseUrl, roomToken)) + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", 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()) ?.subscribe(object : Observer { @@ -332,7 +340,18 @@ class ChatController(args: Bundle) : } private fun handleFromNotification() { - ncApi?.getRooms(credentials, ApiUtils.getUrlForGetRooms(conversationUser?.baseUrl)) + if (ncApi == null) { + return + } + + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", 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 { override fun onSubscribe(d: Disposable) { 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 dda408a6c..0de0eccdf 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt @@ -20,11 +20,13 @@ package com.nextcloud.talk.controllers +import android.annotation.SuppressLint import android.content.Context import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable import android.os.Bundle import android.text.TextUtils +import android.util.Log import android.view.LayoutInflater import android.view.MenuItem import android.view.View @@ -298,6 +300,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA } } + @SuppressLint("LongLogTag") fun submitLobbyChanges() { val state = if ( ( @@ -306,9 +309,17 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA ) as SwitchCompat ).isChecked ) 1 else 0 + + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + ncApi.setLobbyForConversation( ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token), - ApiUtils.getUrlForLobbyForConversation(conversationUser.baseUrl, conversation!!.token), + ApiUtils.getUrlForRoomWebinaryLobby(apiVersion, conversationUser.baseUrl, conversation!!.token), state, conversation!!.lobbyTimer ) @@ -438,9 +449,16 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA } private fun getListOfParticipants() { + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + return + } + ncApi.getPeersForCall( credentials, - ApiUtils.getUrlForParticipants(conversationUser!!.baseUrl, conversationToken) + ApiUtils.getUrlForParticipants(apiVersion, conversationUser!!.baseUrl, conversationToken) ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -527,7 +545,14 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA } private fun fetchRoomInfo() { - ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser!!.baseUrl, conversationToken)) + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", 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()) .subscribe(object : Observer { @@ -701,11 +726,18 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA title(text = participant.displayName) listItemsWithImage(items = items) { dialog, index, _ -> + val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) + + if (apiVersion == null) { + Log.e(TAG, "No supported API version found") + } + if (index == 0) { if (participant.type == Participant.ParticipantType.MODERATOR) { ncApi.demoteModeratorToUser( credentials, - ApiUtils.getUrlForModerators(conversationUser.baseUrl, conversation!!.token), + ApiUtils.getUrlForRoomModerators(apiVersion, conversationUser.baseUrl, + conversation!!.token), participant.userId ) .subscribeOn(Schedulers.io()) @@ -716,7 +748,8 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA } else if (participant.type == Participant.ParticipantType.USER) { ncApi.promoteUserToModerator( credentials, - ApiUtils.getUrlForModerators(conversationUser.baseUrl, conversation!!.token), + ApiUtils.getUrlForRoomModerators(apiVersion, conversationUser.baseUrl, + conversation!!.token), participant.userId ) .subscribeOn(Schedulers.io()) @@ -771,6 +804,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA companion object { + private val TAG = "ConversationInfoController" private const val ID_DELETE_CONVERSATION_DIALOG = 0 } 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 5e51b9b02..86701f3d6 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -53,13 +53,8 @@ public class ApiUtils { /** * @deprecated Please specify the api version you want to use via - * {@link ApiUtils#getUrlForRoomWebinaryLobby(int, String, String)} instead. + * {@link ApiUtils#getUrlForAttendees(int, String, String)} instead. */ - @Deprecated - public static String getUrlForLobbyForConversation(String baseUrl, String token) { - return getUrlForRoomWebinaryLobby(1, baseUrl, token); - } - @Deprecated public static String getUrlForRemovingParticipantFromConversation(String baseUrl, String roomToken, boolean isGuest) { String url = getUrlForParticipants(1, baseUrl, roomToken); @@ -122,16 +117,6 @@ public class ApiUtils { return getUrlForParticipantsActive(1, baseUrl, token); } - - /** - * @deprecated Please specify the api version you want to use via - * {@link ApiUtils#getUrlForParticipants(int, String, String)} instead. - */ - @Deprecated - public static String getUrlForParticipants(String baseUrl, String token) { - return getUrlForParticipants(1, baseUrl, token); - } - public static String getUrlForCapabilities(String baseUrl) { return baseUrl + ocsApiVersion + "/cloud/capabilities"; } @@ -145,15 +130,6 @@ public class ApiUtils { return getUrlForRooms(1, baseUrl); } - /** - * @deprecated Please specify the api version you want to use via - * {@link ApiUtils#getUrlForRoom(int, String, String)} instead. - */ - @Deprecated - public static String getRoom(String baseUrl, String token) { - return getUrlForRoom(1, baseUrl, token); - } - public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) { if (apiName.equals("conversation")) { boolean hasApiV4 = false; @@ -197,6 +173,10 @@ public class ApiUtils { return getUrlForRooms(version, baseUrl) + "/" + token; } + public static String getUrlForAttendees(int version, String baseUrl, String token) { + return getUrlForRoom(version, baseUrl, token) + "/attendees"; + } + public static String getUrlForParticipants(int version, String baseUrl, String token) { return getUrlForRoom(version, baseUrl, token) + "/participants"; }