Fix some kotlin files to allow api switching

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-03 17:13:27 +02:00
parent 115154331d
commit ccd752b4ca
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
4 changed files with 76 additions and 33 deletions

View file

@ -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
)

View file

@ -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<RoomOverall> {
@ -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<RoomsOverall> {
override fun onSubscribe(d: Disposable) {

View file

@ -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<RoomOverall> {
@ -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
}

View file

@ -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";
}