mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-11 14:54:09 +01:00
APIv4 compatibility
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
cc538e48e3
commit
3cd18d50ca
@ -258,23 +258,27 @@ public class CallNotificationController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleFromNotification() {
|
private void handleFromNotification() {
|
||||||
boolean isConversationApiV3 = userBeingCalled.hasSpreedFeatureCapability("conversation-v3");
|
Integer apiVersion = ApiUtils.getApiVersion(userBeingCalled, "conversation", new int[] {4, 3, 1});
|
||||||
if (isConversationApiV3) {
|
if (apiVersion == null) {
|
||||||
ncApi.getRoom(credentials, ApiUtils.getRoomV3(userBeingCalled.getBaseUrl(), roomId))
|
return;
|
||||||
.subscribeOn(Schedulers.io())
|
}
|
||||||
.retry(3)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(new Observer<RoomOverall>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(Disposable d) {
|
|
||||||
disposablesList.add(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
ncApi.getRoom(credentials, ApiUtils.getRoom(apiVersion, userBeingCalled.getBaseUrl(), roomId))
|
||||||
public void onNext(@NotNull RoomOverall roomOverall) {
|
.subscribeOn(Schedulers.io())
|
||||||
currentConversation = roomOverall.getOcs().data;
|
.retry(3)
|
||||||
runAllThings();
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<RoomOverall>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
disposablesList.add(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(@NotNull RoomOverall roomOverall) {
|
||||||
|
currentConversation = roomOverall.getOcs().data;
|
||||||
|
runAllThings();
|
||||||
|
|
||||||
|
if (apiVersion >= 3) {
|
||||||
boolean hasCallFlags = userBeingCalled.hasSpreedFeatureCapability("conversation-call-flags");
|
boolean hasCallFlags = userBeingCalled.hasSpreedFeatureCapability("conversation-call-flags");
|
||||||
if (hasCallFlags) {
|
if (hasCallFlags) {
|
||||||
if (isInCallWithVideo(currentConversation.callFlag)) {
|
if (isInCallWithVideo(currentConversation.callFlag)) {
|
||||||
@ -286,46 +290,19 @@ public class CallNotificationController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressLint("LongLogTag")
|
||||||
public void onError(Throwable e) {
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
Log.e(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
@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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInCallWithVideo(int callFlag) {
|
private boolean isInCallWithVideo(int callFlag) {
|
||||||
|
@ -26,6 +26,7 @@ import com.nextcloud.talk.BuildConfig;
|
|||||||
import com.nextcloud.talk.R;
|
import com.nextcloud.talk.R;
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||||
import com.nextcloud.talk.models.RetrofitBucket;
|
import com.nextcloud.talk.models.RetrofitBucket;
|
||||||
|
import com.nextcloud.talk.models.database.UserEntity;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -37,6 +38,7 @@ import okhttp3.Credentials;
|
|||||||
public class ApiUtils {
|
public class ApiUtils {
|
||||||
private static String ocsApiVersion = "/ocs/v2.php";
|
private static String ocsApiVersion = "/ocs/v2.php";
|
||||||
private static String spreedApiVersion = "/apps/spreed/api/v1";
|
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";
|
private static String userAgent = "Mozilla/5.0 (Android) Nextcloud-Talk v";
|
||||||
|
|
||||||
@ -122,12 +124,30 @@ public class ApiUtils {
|
|||||||
return baseUrl + ocsApiVersion + spreedApiVersion + "/room";
|
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) {
|
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) {
|
public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) {
|
||||||
return baseUrl + ocsApiVersion + "/apps/spreed/api/v3" + "/room/" + token;
|
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,
|
public static RetrofitBucket getRetrofitBucketForCreateRoom(String baseUrl, String roomType,
|
||||||
|
Loading…
Reference in New Issue
Block a user