mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-26 23:25:20 +03:00
Allow to inject the version into the chat api
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
cf23a3d87d
commit
e6d869d431
3 changed files with 65 additions and 20 deletions
|
@ -1142,9 +1142,16 @@ class ChatController(args: Bundle) :
|
|||
private fun sendMessage(message: CharSequence, replyTo: Int?) {
|
||||
|
||||
if (conversationUser != null) {
|
||||
val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
||||
|
||||
if (apiVersion == null) {
|
||||
Log.e(TAG, "No supported API version found")
|
||||
return
|
||||
}
|
||||
|
||||
ncApi!!.sendChatMessage(
|
||||
credentials,
|
||||
ApiUtils.getUrlForChat(conversationUser.baseUrl, roomToken),
|
||||
ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl, roomToken),
|
||||
message,
|
||||
conversationUser.displayName,
|
||||
replyTo
|
||||
|
@ -1244,11 +1251,23 @@ class ChatController(args: Bundle) :
|
|||
}
|
||||
|
||||
if (!wasDetached) {
|
||||
var apiVersion: Int?
|
||||
// FIXME this is a best guess, guests would need to get the capabilities themselves
|
||||
apiVersion = 1
|
||||
if (conversationUser != null) {
|
||||
apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
||||
|
||||
if (apiVersion == null) {
|
||||
Log.e(TAG, "No supported API version found")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (lookIntoFuture > 0) {
|
||||
val finalTimeout = timeout
|
||||
ncApi?.pullChatMessages(
|
||||
credentials,
|
||||
ApiUtils.getUrlForChat(conversationUser?.baseUrl, roomToken), fieldMap
|
||||
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken), fieldMap
|
||||
)
|
||||
?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -1277,7 +1296,7 @@ class ChatController(args: Bundle) :
|
|||
} else {
|
||||
ncApi?.pullChatMessages(
|
||||
credentials,
|
||||
ApiUtils.getUrlForChat(conversationUser?.baseUrl, roomToken), fieldMap
|
||||
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken), fieldMap
|
||||
)
|
||||
?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -1667,9 +1686,17 @@ class ChatController(args: Bundle) :
|
|||
true
|
||||
}
|
||||
R.id.action_delete_message -> {
|
||||
val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
||||
|
||||
if (apiVersion == null) {
|
||||
Log.e(TAG, "No supported API version found")
|
||||
}
|
||||
|
||||
|
||||
ncApi?.deleteChatMessage(
|
||||
credentials,
|
||||
ApiUtils.getUrlForMessageDeletion(conversationUser?.baseUrl, roomToken, message?.id)
|
||||
ApiUtils.getUrlForChatMessage(apiVersion, conversationUser?.baseUrl, roomToken,
|
||||
message?.id)
|
||||
)?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<ChatOverallSingleMessage> {
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
|
||||
package com.nextcloud.talk.presenters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -47,6 +49,7 @@ import java.util.List;
|
|||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class MentionAutocompletePresenter extends RecyclerViewPresenter<Mention> implements FlexibleAdapter.OnItemClickListener {
|
||||
private static final String TAG = "MentionAutocompletePresenter";
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
@Inject
|
||||
|
@ -81,6 +84,7 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter<Mention>
|
|||
return adapter;
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
protected void onQuery(@Nullable CharSequence query) {
|
||||
|
||||
|
@ -91,9 +95,17 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter<Mention>
|
|||
queryString = "";
|
||||
}
|
||||
|
||||
Integer apiVersion = ApiUtils.getChatApiVersion(currentUser, new int[] {1});
|
||||
|
||||
if (apiVersion == null) {
|
||||
Log.e(TAG, "No supported API version found", new Exception("No supported API version found"));
|
||||
return;
|
||||
}
|
||||
|
||||
adapter.setFilter(queryString);
|
||||
ncApi.getMentionAutocompleteSuggestions(ApiUtils.getCredentials(currentUser.getUsername(), currentUser
|
||||
.getToken()), ApiUtils.getUrlForMentionSuggestions(currentUser.getBaseUrl(), roomToken),
|
||||
ncApi.getMentionAutocompleteSuggestions(
|
||||
ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()),
|
||||
ApiUtils.getUrlForMentionSuggestions(apiVersion, currentUser.getBaseUrl(), roomToken),
|
||||
queryString, 5)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
|
|
@ -154,6 +154,16 @@ public class ApiUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Integer getChatApiVersion(UserEntity capabilities, int[] versions) {
|
||||
for (int version : versions) {
|
||||
if (version == 1 && capabilities.hasSpreedFeatureCapability("chat-v2")) {
|
||||
// Do not question that chat-v2 capability shows the availability of api/v1/ endpoint *see no evil*
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String getUrlForApi(int version, String baseUrl) {
|
||||
return baseUrl + spreedApiBase + version;
|
||||
}
|
||||
|
@ -213,6 +223,16 @@ public class ApiUtils {
|
|||
public static String getUrlForCall(int version, String baseUrl, String token) {
|
||||
return getUrlForApi(version, baseUrl) + "/call/" + token;
|
||||
}
|
||||
public static String getUrlForChat(int version, String baseUrl, String token) {
|
||||
return getUrlForApi(version, baseUrl) + "/chat/" + token;
|
||||
}
|
||||
|
||||
public static String getUrlForMentionSuggestions(int version, String baseUrl, String token) {
|
||||
return getUrlForChat(version, baseUrl, token) + "/mentions";
|
||||
}
|
||||
public static String getUrlForChatMessage(int version, String baseUrl, String token, String messageId) {
|
||||
return getUrlForChat(version, baseUrl, token) + "/" + messageId;
|
||||
}
|
||||
|
||||
public static String getUrlForSignaling(int version, String baseUrl) {
|
||||
return getUrlForApi(version, baseUrl) + "/signaling";
|
||||
|
@ -285,16 +305,6 @@ public class ApiUtils {
|
|||
return getUrlForCall(1, baseUrl, token) + "/ping";
|
||||
}
|
||||
|
||||
public static String getUrlForChat(String baseUrl, String token) {
|
||||
// FIXME Introduce API version
|
||||
return baseUrl + ocsApiVersion + spreedApiVersion + "/chat/" + token;
|
||||
}
|
||||
|
||||
public static String getUrlForMentionSuggestions(String baseUrl, String token) {
|
||||
// FIXME Introduce API version
|
||||
return getUrlForChat(baseUrl, token) + "/mentions";
|
||||
}
|
||||
|
||||
public static String getUrlForUserProfile(String baseUrl) {
|
||||
return baseUrl + ocsApiVersion + "/cloud/user";
|
||||
}
|
||||
|
@ -363,10 +373,6 @@ public class ApiUtils {
|
|||
return baseUrl + "/remote.php/dav/files/" + user + "/" + remotePath;
|
||||
}
|
||||
|
||||
public static String getUrlForMessageDeletion(String baseUrl, String token, String messageId) {
|
||||
return getUrlForChat(baseUrl, token) + "/" + messageId;
|
||||
}
|
||||
|
||||
public static String getUrlForTempAvatar(String baseUrl) {
|
||||
return baseUrl + ocsApiVersion + "/apps/spreed/temp-user-avatar";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue