Change version to be specific to conversations api

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-04 07:19:12 +02:00
parent e6d869d431
commit 529541d896
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
15 changed files with 45 additions and 55 deletions

View File

@ -303,7 +303,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
var inCallOnDifferentDevice = false var inCallOnDifferentDevice = false
val apiVersion = ApiUtils.getApiVersion(signatureVerification.userEntity, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(signatureVerification.userEntity, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")

View File

@ -231,7 +231,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
val roomType = "1" val roomType = "1"
val currentUser = userUtils.currentUser ?: return val currentUser = userUtils.currentUser ?: return
val apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -258,7 +258,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")) {
val apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")

View File

@ -441,7 +441,7 @@ public class CallController extends BaseController {
} }
private void handleFromNotification() { private void handleFromNotification() {
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -1248,8 +1248,7 @@ public class CallController extends BaseController {
private void joinRoomAndCall() { private void joinRoomAndCall() {
callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession(); callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession();
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
return; return;
@ -1309,7 +1308,7 @@ public class CallController extends BaseController {
inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue(); inCallFlag = (int) Participant.ParticipantFlags.IN_CALL_WITH_AUDIO_AND_VIDEO.getValue();
} }
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -1648,7 +1647,7 @@ public class CallController extends BaseController {
} }
private void hangupNetworkCalls(boolean shutDownView) { private void hangupNetworkCalls(boolean shutDownView) {
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -1690,8 +1689,7 @@ public class CallController extends BaseController {
} }
private void leaveRoom(boolean shutDownView) { private void leaveRoom(boolean shutDownView) {
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
return; return;
@ -1790,7 +1788,7 @@ public class CallController extends BaseController {
private void getPeersForCall() { private void getPeersForCall() {
Log.d(TAG, "getPeersForCall"); Log.d(TAG, "getPeersForCall");
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -210,7 +210,7 @@ public class CallNotificationController extends BaseController {
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
private void checkIfAnyParticipantsRemainInRoom() { private void checkIfAnyParticipantsRemainInRoom() {
Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -267,7 +267,7 @@ public class CallNotificationController extends BaseController {
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
private void handleFromNotification() { private void handleFromNotification() {
Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {4, 3, 1}); Integer apiVersion = ApiUtils.getConversationApiVersion(userBeingCalled, new int[] {4, 3, 1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
return; return;

View File

@ -294,7 +294,7 @@ class ChatController(args: Bundle) :
} }
if (conversationUser != null) { if (conversationUser != null) {
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -344,7 +344,7 @@ class ChatController(args: Bundle) :
return return
} }
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -977,7 +977,7 @@ class ChatController(args: Bundle) :
if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) || if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) ||
currentConversation?.sessionId == "0" currentConversation?.sessionId == "0"
) { ) {
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -1051,7 +1051,7 @@ class ChatController(args: Bundle) :
} }
private fun leaveRoom() { private fun leaveRoom() {
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -1806,7 +1806,7 @@ class ChatController(args: Bundle) :
currentConversation?.name != userMentionClickEvent.userId currentConversation?.name != userMentionClickEvent.userId
) { ) {
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")

View File

@ -288,7 +288,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
userId = selectedUserIds.iterator().next(); userId = selectedUserIds.iterator().next();
} }
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -318,8 +318,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_TOKEN(), roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId()); bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), roomOverall.getOcs().getData().getRoomId());
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
new int[] {1});
if (apiVersion != null && currentUser.hasSpreedFeatureCapability("chat-v2")) { if (apiVersion != null && currentUser.hasSpreedFeatureCapability("chat-v2")) {
ncApi.getRoom(credentials, ncApi.getRoom(credentials,
@ -861,7 +860,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
roomType = "2"; roomType = "2";
} }
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -310,7 +310,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
).isChecked ).isChecked
) 1 else 0 ) 1 else 0
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -449,7 +449,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
} }
private fun getListOfParticipants() { private fun getListOfParticipants() {
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -545,7 +545,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
} }
private fun fetchRoomInfo() { private fun fetchRoomInfo() {
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")
@ -726,7 +726,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
title(text = participant.displayName) title(text = participant.displayName)
listItemsWithImage(items = items) { dialog, index, _ -> listItemsWithImage(items = items) { dialog, index, _ ->
val apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", intArrayOf(1)) val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(1))
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found") Log.e(TAG, "No supported API version found")

View File

@ -418,7 +418,7 @@ public class ConversationsListController extends BaseController implements Searc
callItems = new ArrayList<>(); callItems = new ArrayList<>();
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {4, 1}); Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {4, 1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
return; return;

View File

@ -193,8 +193,7 @@ public class OperationsMenuController extends BaseController {
credentials = null; credentials = null;
} }
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -402,8 +401,7 @@ public class OperationsMenuController extends BaseController {
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
private void performGroupCallWorkaround(String credentials) { private void performGroupCallWorkaround(String credentials) {
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
@ -567,7 +565,7 @@ public class OperationsMenuController extends BaseController {
localInvitedGroups.remove(0); localInvitedGroups.remove(0);
} }
Integer apiVersion = ApiUtils.getApiVersion(currentUser, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -70,7 +70,7 @@ public class AddParticipantsToConversation extends Worker {
public Result doWork() { public Result doWork() {
UserEntity user = userUtils.getUserWithInternalId(data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1)); UserEntity user = userUtils.getUserWithInternalId(data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1));
Integer apiVersion = ApiUtils.getApiVersion(user, "conversation", new int[] {1}); Integer apiVersion = ApiUtils.getConversationApiVersion(user, new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -80,8 +80,7 @@ public class DeleteConversationWorker extends Worker {
UserEntity operationUser = userUtils.getUserWithId(operationUserId); UserEntity operationUser = userUtils.getUserWithId(operationUserId);
if (operationUser != null) { if (operationUser != null) {
Integer apiVersion = ApiUtils.getApiVersion(operationUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -87,8 +87,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);
Integer apiVersion = ApiUtils.getApiVersion(operationUser, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -152,8 +152,7 @@ public class NotificationWorker extends Worker {
importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue()); importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
} }
Integer apiVersion = ApiUtils.getApiVersion(userEntity, "conversation", Integer apiVersion = ApiUtils.getConversationApiVersion(userEntity, new int[] {1});
new int[] {1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));

View File

@ -109,30 +109,28 @@ public class ApiUtils {
return baseUrl + ocsApiVersion + "/cloud/capabilities"; return baseUrl + ocsApiVersion + "/cloud/capabilities";
} }
public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) { public static Integer getConversationApiVersion(UserEntity capabilities, int[] versions) {
if (apiName.equals("conversation")) { boolean hasApiV4 = false;
boolean hasApiV4 = false; for (int version : versions) {
for (int version : versions) { hasApiV4 |= version == 4;
hasApiV4 |= version == 4; }
}
if (!hasApiV4) { if (!hasApiV4) {
Exception e = new Exception("Api call did not try conversation-v4 api"); Exception e = new Exception("Api call did not try conversation-v4 api");
Log.d(TAG, e.getMessage(), e); Log.d(TAG, e.getMessage(), e);
} }
}
for (int version : versions) { for (int version : versions) {
if (capabilities.hasSpreedFeatureCapability(apiName + "-v" + version)) { if (capabilities.hasSpreedFeatureCapability("conversation-v" + version)) {
return version; return version;
} }
// Fallback for old API versions // Fallback for old API versions
if (apiName.equals("conversation") && (version == 1 || version == 2)) { if ((version == 1 || version == 2)) {
if (capabilities.hasSpreedFeatureCapability(apiName + "-v2")) { if (capabilities.hasSpreedFeatureCapability("conversation-v2")) {
return version; return version;
} }
if (version == 1 && capabilities.hasSpreedFeatureCapability(apiName)) { if (version == 1 && capabilities.hasSpreedFeatureCapability("conversation")) {
return version; return version;
} }
} }

View File

@ -97,7 +97,7 @@ public class DatabaseStorageModule implements StorageModule {
intValue = 0; intValue = 0;
} }
Integer apiVersion = ApiUtils.getApiVersion(conversationUser, "conversation", new int[] {4, 1}); Integer apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[] {4, 1});
if (apiVersion == null) { if (apiVersion == null) {
Log.e(TAG, "No supported API version found", new Exception("No supported API version found")); Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
} }