mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 05:25:31 +03:00
add proper API version detection
don't let switch fall through make api versions constants Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
1521e13e21
commit
de085df3bc
3 changed files with 14 additions and 11 deletions
|
@ -2324,7 +2324,7 @@ class ChatController(args: Bundle) :
|
|||
ncApi!!.setChatReadMarker(
|
||||
credentials,
|
||||
ApiUtils.getUrlForSetChatReadMarker(
|
||||
1,
|
||||
ApiUtils.getChatApiVersion(conversationUser, intArrayOf(ApiUtils.APIv1)),
|
||||
conversationUser?.baseUrl,
|
||||
roomToken
|
||||
),
|
||||
|
|
|
@ -280,7 +280,8 @@ public class OperationsMenuController extends BaseController {
|
|||
}
|
||||
|
||||
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
|
||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, 1});
|
||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, ApiUtils.APIv1});
|
||||
int chatApiVersion = ApiUtils.getChatApiVersion(currentUser, new int[] {ApiUtils.APIv1});
|
||||
|
||||
switch (operationCode) {
|
||||
case 2:
|
||||
|
@ -483,9 +484,8 @@ public class OperationsMenuController extends BaseController {
|
|||
|
||||
break;
|
||||
case 96:
|
||||
// TODO: why does it break with v4?
|
||||
ncApi.setChatReadMarker(credentials,
|
||||
ApiUtils.getUrlForSetChatReadMarker(1,
|
||||
ApiUtils.getUrlForSetChatReadMarker(chatApiVersion,
|
||||
currentUser.getBaseUrl(),
|
||||
conversation.getToken()),
|
||||
conversation.lastMessage.jsonMessageId)
|
||||
|
@ -493,6 +493,7 @@ public class OperationsMenuController extends BaseController {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.retry(1)
|
||||
.subscribe(genericOperationsObserver);
|
||||
break;
|
||||
case 97:
|
||||
case 98:
|
||||
if (operationCode == 97) {
|
||||
|
|
|
@ -40,6 +40,8 @@ import androidx.annotation.Nullable;
|
|||
import okhttp3.Credentials;
|
||||
|
||||
public class ApiUtils {
|
||||
public static final int APIv1 = 1;
|
||||
public static final int APIv2 = 2;
|
||||
public static final int APIv3 = 3;
|
||||
public static final int APIv4 = 4;
|
||||
private static final String TAG = "ApiUtils";
|
||||
|
@ -59,7 +61,7 @@ public class ApiUtils {
|
|||
*/
|
||||
@Deprecated
|
||||
public static String getUrlForRemovingParticipantFromConversation(String baseUrl, String roomToken, boolean isGuest) {
|
||||
String url = getUrlForParticipants(1, baseUrl, roomToken);
|
||||
String url = getUrlForParticipants(APIv1, baseUrl, roomToken);
|
||||
|
||||
if (isGuest) {
|
||||
url += "/guests";
|
||||
|
@ -121,7 +123,7 @@ public class ApiUtils {
|
|||
public static int getConversationApiVersion(UserEntity user, int[] versions) throws NoSupportedApiException {
|
||||
boolean hasApiV4 = false;
|
||||
for (int version : versions) {
|
||||
hasApiV4 |= version == 4;
|
||||
hasApiV4 |= version == APIv4;
|
||||
}
|
||||
|
||||
if (!hasApiV4) {
|
||||
|
@ -135,11 +137,11 @@ public class ApiUtils {
|
|||
}
|
||||
|
||||
// Fallback for old API versions
|
||||
if ((version == 1 || version == 2)) {
|
||||
if ((version == APIv1 || version == APIv2)) {
|
||||
if (CapabilitiesUtil.hasSpreedFeatureCapability(user, "conversation-v2")) {
|
||||
return version;
|
||||
}
|
||||
if (version == 1 &&
|
||||
if (version == APIv1 &&
|
||||
CapabilitiesUtil.hasSpreedFeatureCapability(user, "mention-flag") &&
|
||||
!CapabilitiesUtil.hasSpreedFeatureCapability(user, "conversation-v4")) {
|
||||
return version;
|
||||
|
@ -155,13 +157,13 @@ public class ApiUtils {
|
|||
return version;
|
||||
}
|
||||
|
||||
if (version == 2 &&
|
||||
if (version == APIv2 &&
|
||||
CapabilitiesUtil.hasSpreedFeatureCapability(user, "sip-support") &&
|
||||
!CapabilitiesUtil.hasSpreedFeatureCapability(user, "signaling-v3")) {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (version == 1 &&
|
||||
if (version == APIv1 &&
|
||||
!CapabilitiesUtil.hasSpreedFeatureCapability(user, "signaling-v3")) {
|
||||
// Has no capability, we just assume it is always there when there is no v3 or later
|
||||
return version;
|
||||
|
@ -172,7 +174,7 @@ public class ApiUtils {
|
|||
|
||||
public static int getChatApiVersion(UserEntity user, int[] versions) throws NoSupportedApiException {
|
||||
for (int version : versions) {
|
||||
if (version == 1 && CapabilitiesUtil.hasSpreedFeatureCapability(user, "chat-v2")) {
|
||||
if (version == APIv1 && CapabilitiesUtil.hasSpreedFeatureCapability(user, "chat-v2")) {
|
||||
// Do not question that chat-v2 capability shows the availability of api/v1/ endpoint *see no evil*
|
||||
return version;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue