mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
Merge pull request #1219 from nextcloud/feature/apiv4/add-apiv4-for-easy-conversation-api-calls
[apiv4] Add apiv4 for easy conversation api calls
This commit is contained in:
commit
4bf570ac35
@ -229,7 +229,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||||||
val roomType = "1"
|
val roomType = "1"
|
||||||
val currentUser = userUtils.currentUser ?: return
|
val currentUser = userUtils.currentUser ?: return
|
||||||
|
|
||||||
val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(1))
|
val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
|
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
|
||||||
val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
|
val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
|
||||||
apiVersion, currentUser.baseUrl, roomType,
|
apiVersion, currentUser.baseUrl, roomType,
|
||||||
@ -250,6 +250,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||||||
bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs.data.token)
|
bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs.data.token)
|
||||||
bundle.putString(KEY_ROOM_ID, roomOverall.ocs.data.roomId)
|
bundle.putString(KEY_ROOM_ID, roomOverall.ocs.data.roomId)
|
||||||
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
|
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
|
||||||
|
// FIXME once APIv2 or later is used only, the createRoom already returns all the data
|
||||||
ncApi.getRoom(
|
ncApi.getRoom(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForRoom(
|
ApiUtils.getUrlForRoom(
|
||||||
|
@ -437,7 +437,7 @@ public class CallController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleFromNotification() {
|
private void handleFromNotification() {
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, baseUrl))
|
ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, baseUrl))
|
||||||
.retry(3)
|
.retry(3)
|
||||||
@ -1217,7 +1217,7 @@ public class CallController extends BaseController {
|
|||||||
private void joinRoomAndCall() {
|
private void joinRoomAndCall() {
|
||||||
callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession();
|
callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession();
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
if (TextUtils.isEmpty(callSession)) {
|
if (TextUtils.isEmpty(callSession)) {
|
||||||
ncApi.joinRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken),
|
ncApi.joinRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken),
|
||||||
@ -1591,7 +1591,7 @@ public class CallController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void leaveRoom(boolean shutDownView) {
|
private void leaveRoom(boolean shutDownView) {
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
ncApi.leaveRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken))
|
ncApi.leaveRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
@ -260,7 +260,8 @@ public class CallNotificationController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleFromNotification() {
|
private void handleFromNotification() {
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {4, 3, 1});
|
int apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {ApiUtils.APIv4,
|
||||||
|
ApiUtils.APIv3, 1});
|
||||||
|
|
||||||
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userBeingCalled.getBaseUrl(), roomId))
|
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userBeingCalled.getBaseUrl(), roomId))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
@ -292,7 +292,7 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
|
|
||||||
ncApi?.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser.baseUrl, roomToken))
|
ncApi?.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser.baseUrl, roomToken))
|
||||||
?.subscribeOn(Schedulers.io())
|
?.subscribeOn(Schedulers.io())
|
||||||
@ -336,7 +336,7 @@ class ChatController(args: Bundle) :
|
|||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Can this be called for guests?
|
// FIXME Can this be called for guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
ncApi?.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, conversationUser?.baseUrl))
|
ncApi?.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, conversationUser?.baseUrl))
|
||||||
@ -933,7 +933,7 @@ class ChatController(args: Bundle) :
|
|||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Fix API checking with guests?
|
// FIXME Fix API checking with guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
ncApi?.joinRoom(
|
ncApi?.joinRoom(
|
||||||
@ -1004,7 +1004,7 @@ class ChatController(args: Bundle) :
|
|||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Fix API checking with guests?
|
// FIXME Fix API checking with guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
ncApi?.leaveRoom(
|
ncApi?.leaveRoom(
|
||||||
@ -1627,7 +1627,7 @@ class ChatController(args: Bundle) :
|
|||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Fix API checking with guests?
|
// FIXME Fix API checking with guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
ncApi?.deleteChatMessage(
|
ncApi?.deleteChatMessage(
|
||||||
@ -1750,7 +1750,7 @@ class ChatController(args: Bundle) :
|
|||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Fix API checking with guests?
|
// FIXME Fix API checking with guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
|
val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
|
||||||
|
@ -289,7 +289,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
userId = selectedUserIds.iterator().next();
|
userId = selectedUserIds.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion,
|
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion,
|
||||||
currentUser.getBaseUrl(),
|
currentUser.getBaseUrl(),
|
||||||
roomType,
|
roomType,
|
||||||
@ -314,6 +314,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId());
|
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId());
|
||||||
|
|
||||||
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
|
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
|
||||||
|
// FIXME once APIv2 or later is used only, the createRoom already returns all the data
|
||||||
ncApi.getRoom(credentials,
|
ncApi.getRoom(credentials,
|
||||||
ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(),
|
ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(),
|
||||||
roomOverall.getOcs().getData().getToken()))
|
roomOverall.getOcs().getData().getToken()))
|
||||||
@ -853,7 +854,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
roomType = "2";
|
roomType = "2";
|
||||||
}
|
}
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion,
|
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(apiVersion,
|
||||||
currentUser.getBaseUrl(),
|
currentUser.getBaseUrl(),
|
||||||
|
@ -307,7 +307,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
).isChecked
|
).isChecked
|
||||||
) 1 else 0
|
) 1 else 0
|
||||||
|
|
||||||
val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
|
|
||||||
ncApi.setLobbyForConversation(
|
ncApi.setLobbyForConversation(
|
||||||
ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token),
|
ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token),
|
||||||
@ -539,7 +539,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Fix API checking with guests?
|
// FIXME Fix API checking with guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser!!.baseUrl, conversationToken))
|
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser!!.baseUrl, conversationToken))
|
||||||
|
@ -415,7 +415,7 @@ public class ConversationsListController extends BaseController implements Searc
|
|||||||
|
|
||||||
callItems = new ArrayList<>();
|
callItems = new ArrayList<>();
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {4, 1});
|
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, ApiUtils.APIv3, 1});
|
||||||
|
|
||||||
roomsQueryDisposable = ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion,
|
roomsQueryDisposable = ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion,
|
||||||
currentUser.getBaseUrl()))
|
currentUser.getBaseUrl()))
|
||||||
|
@ -191,7 +191,7 @@ public class OperationsMenuController extends BaseController {
|
|||||||
// FIXME joining a public link we need to check other capabilities
|
// FIXME joining a public link we need to check other capabilities
|
||||||
apiVersion = 1;
|
apiVersion = 1;
|
||||||
} else {
|
} else {
|
||||||
apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
|
apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ public class OperationsMenuController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void performGroupCallWorkaround(String credentials) {
|
private void performGroupCallWorkaround(String credentials) {
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomPublic(apiVersion, currentUser.getBaseUrl(),
|
ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomPublic(apiVersion, currentUser.getBaseUrl(),
|
||||||
conversation.getToken()))
|
conversation.getToken()))
|
||||||
|
@ -75,7 +75,7 @@ public class DeleteConversationWorker extends Worker {
|
|||||||
UserEntity operationUser = userUtils.getUserWithId(operationUserId);
|
UserEntity operationUser = userUtils.getUserWithId(operationUserId);
|
||||||
|
|
||||||
if (operationUser != null) {
|
if (operationUser != null) {
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
String credentials = ApiUtils.getCredentials(operationUser.getUsername(), operationUser.getToken());
|
String credentials = ApiUtils.getCredentials(operationUser.getUsername(), operationUser.getToken());
|
||||||
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
|
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
|
||||||
|
@ -83,7 +83,7 @@ public class LeaveConversationWorker extends Worker {
|
|||||||
EventStatus eventStatus = new EventStatus(operationUser.getId(),
|
EventStatus eventStatus = new EventStatus(operationUser.getId(),
|
||||||
EventStatus.EventType.CONVERSATION_UPDATE, true);
|
EventStatus.EventType.CONVERSATION_UPDATE, true);
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForParticipantsSelf(apiVersion,
|
ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForParticipantsSelf(apiVersion,
|
||||||
operationUser.getBaseUrl(),
|
operationUser.getBaseUrl(),
|
||||||
|
@ -152,7 +152,7 @@ public class NotificationWorker extends Worker {
|
|||||||
importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
|
importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(userEntity, new int[] {1});
|
int apiVersion = ApiUtils.getConversationApiVersion(userEntity, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userEntity.getBaseUrl(),
|
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userEntity.getBaseUrl(),
|
||||||
intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())))
|
intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())))
|
||||||
|
@ -37,6 +37,8 @@ import androidx.annotation.Nullable;
|
|||||||
import okhttp3.Credentials;
|
import okhttp3.Credentials;
|
||||||
|
|
||||||
public class ApiUtils {
|
public class ApiUtils {
|
||||||
|
public static final int APIv3 = 3;
|
||||||
|
public static final int APIv4 = 4;
|
||||||
private static final String TAG = "ApiUtils";
|
private static final String TAG = "ApiUtils";
|
||||||
private static final String ocsApiVersion = "/ocs/v2.php";
|
private static final String ocsApiVersion = "/ocs/v2.php";
|
||||||
private static final String spreedApiVersion = "/apps/spreed/api/v1";
|
private static final String spreedApiVersion = "/apps/spreed/api/v1";
|
||||||
|
@ -93,7 +93,7 @@ public class DatabaseStorageModule implements StorageModule {
|
|||||||
intValue = 0;
|
intValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {4, 1});
|
int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()),
|
ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()),
|
||||||
ApiUtils.getUrlForRoomNotificationLevel(apiVersion, conversationUser.getBaseUrl(),
|
ApiUtils.getUrlForRoomNotificationLevel(apiVersion, conversationUser.getBaseUrl(),
|
||||||
|
Loading…
Reference in New Issue
Block a user