APIv4 compatibility

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-04-23 11:54:41 +02:00
parent cc538e48e3
commit 3cd18d50ca
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 52 additions and 55 deletions

View File

@ -258,9 +258,12 @@ public class CallNotificationController extends BaseController {
}
private void handleFromNotification() {
boolean isConversationApiV3 = userBeingCalled.hasSpreedFeatureCapability("conversation-v3");
if (isConversationApiV3) {
ncApi.getRoom(credentials, ApiUtils.getRoomV3(userBeingCalled.getBaseUrl(), roomId))
Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {4, 3, 1});
if (apiVersion == null) {
return;
}
ncApi.getRoom(credentials, ApiUtils.getRoom(apiVersion, userBeingCalled.getBaseUrl(), roomId))
.subscribeOn(Schedulers.io())
.retry(3)
.observeOn(AndroidSchedulers.mainThread())
@ -275,6 +278,7 @@ public class CallNotificationController extends BaseController {
currentConversation = roomOverall.getOcs().data;
runAllThings();
if (apiVersion >= 3) {
boolean hasCallFlags = userBeingCalled.hasSpreedFeatureCapability("conversation-call-flags");
if (hasCallFlags) {
if (isInCallWithVideo(currentConversation.callFlag)) {
@ -286,38 +290,12 @@ public class CallNotificationController extends BaseController {
}
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
ncApi.getRoom(credentials, ApiUtils.getRoom(userBeingCalled.getBaseUrl(), roomId))
.subscribeOn(Schedulers.io())
.retry(3)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RoomOverall>() {
@Override
public void onSubscribe(Disposable d) {
disposablesList.add(d);
}
@SuppressLint("LongLogTag")
@Override
public void onNext(@NotNull RoomOverall roomOverall) {
currentConversation = roomOverall.getOcs().data;
runAllThings();
}
@Override
public void onError(Throwable e) {
Log.e(TAG, e.getMessage(), e);
}
@Override
@ -326,7 +304,6 @@ public class CallNotificationController extends BaseController {
}
});
}
}
private boolean isInCallWithVideo(int callFlag) {
return (Participant.ParticipantFlags.IN_CALL_WITH_VIDEO.getValue() == callFlag

View File

@ -26,6 +26,7 @@ import com.nextcloud.talk.BuildConfig;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.models.database.UserEntity;
import java.util.HashMap;
import java.util.Map;
@ -37,6 +38,7 @@ import okhttp3.Credentials;
public class ApiUtils {
private static String ocsApiVersion = "/ocs/v2.php";
private static String spreedApiVersion = "/apps/spreed/api/v1";
private static String spreedApiBase = ocsApiVersion + "/apps/spreed/api/v";
private static String userAgent = "Mozilla/5.0 (Android) Nextcloud-Talk v";
@ -122,12 +124,30 @@ public class ApiUtils {
return baseUrl + ocsApiVersion + spreedApiVersion + "/room";
}
/**
* @deprecated Please specify the api version you want to use via
* {@link ApiUtils#getRoom(int, String, String)} instead.
*/
@Deprecated
public static String getRoom(String baseUrl, String token) {
return baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token;
return getRoom(1, baseUrl, token);
}
public static String getRoomV3(String baseUrl, String token) {
return baseUrl + ocsApiVersion + "/apps/spreed/api/v3" + "/room/" + token;
public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) {
for (int version : versions) {
if (capabilities.hasSpreedFeatureCapability(apiName + "-v" + version)) {
return version;
}
}
return null;
}
protected static String getApi(int version, String baseUrl) {
return baseUrl + spreedApiBase + version;
}
public static String getRoom(int version, String baseUrl, String token) {
return getApi(version, baseUrl) + "/room/" + token;
}
public static RetrofitBucket getRetrofitBucketForCreateRoom(String baseUrl, String roomType,