mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Prepare chat controller for menu operations
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
6c5860ac97
commit
919e349ac9
@ -92,6 +92,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -125,15 +126,16 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
private List<Disposable> disposableList = new ArrayList<>();
|
private List<Disposable> disposableList = new ArrayList<>();
|
||||||
private String conversationName;
|
private String conversationName;
|
||||||
private String roomToken;
|
private String roomToken;
|
||||||
private UserEntity currentUser;
|
private UserEntity conversationUser;
|
||||||
private String roomPassword;
|
private String roomPassword;
|
||||||
|
private String credentials;
|
||||||
|
private String baseUrl;
|
||||||
private Call currentCall;
|
private Call currentCall;
|
||||||
private boolean inChat = false;
|
private boolean inChat = false;
|
||||||
private boolean historyRead = false;
|
private boolean historyRead = false;
|
||||||
private int globalLastKnownFutureMessageId = -1;
|
private int globalLastKnownFutureMessageId = -1;
|
||||||
private int globalLastKnownPastMessageId = -1;
|
private int globalLastKnownPastMessageId = -1;
|
||||||
private MessagesListAdapter<ChatMessage> adapter;
|
private MessagesListAdapter<ChatMessage> adapter;
|
||||||
private Menu globalMenu;
|
|
||||||
|
|
||||||
private Autocomplete mentionAutocomplete;
|
private Autocomplete mentionAutocomplete;
|
||||||
private LinearLayoutManager layoutManager;
|
private LinearLayoutManager layoutManager;
|
||||||
@ -149,9 +151,16 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
super(args);
|
super(args);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME);
|
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME);
|
||||||
this.currentUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY));
|
if (args.containsKey(BundleKeys.KEY_USER_ENTITY)) {
|
||||||
|
this.conversationUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY));
|
||||||
|
}
|
||||||
|
|
||||||
this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN);
|
this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN);
|
||||||
this.roomPassword = args.getString(BundleKeys.KEY_ROOM_PASSWORD, "");
|
|
||||||
|
if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) {
|
||||||
|
this.currentCall = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION));
|
||||||
|
}
|
||||||
|
this.baseUrl = args.getString(BundleKeys.KEY_MODIFIED_BASE_URL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -182,7 +191,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
holdersConfig.setOutcoming(MagicOutcomingTextMessageViewHolder.class,
|
holdersConfig.setOutcoming(MagicOutcomingTextMessageViewHolder.class,
|
||||||
R.layout.item_custom_outcoming_text_message);
|
R.layout.item_custom_outcoming_text_message);
|
||||||
|
|
||||||
adapter = new MessagesListAdapter<>(currentUser.getUserId(), holdersConfig, new ImageLoader() {
|
adapter = new MessagesListAdapter<>(conversationUser.getUserId(), holdersConfig, new ImageLoader() {
|
||||||
@Override
|
@Override
|
||||||
public void loadImage(ImageView imageView, String url) {
|
public void loadImage(ImageView imageView, String url) {
|
||||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||||
@ -241,8 +250,40 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (adapterWasNull) {
|
if (adapterWasNull) {
|
||||||
|
UserEntity currentUser = userUtils.getCurrentUser();
|
||||||
|
if (conversationUser != null && !currentUser.equals(conversationUser)) {
|
||||||
|
userUtils.createOrUpdateUser(null,
|
||||||
|
null, null, null,
|
||||||
|
null, true, null, currentUser.getId(), null, null)
|
||||||
|
.subscribe(new Observer<UserEntity>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(UserEntity userEntity) {
|
||||||
joinRoomWithPassword();
|
joinRoomWithPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (conversationUser == null) {
|
||||||
|
conversationUser = new UserEntity();
|
||||||
|
conversationUser.setDisplayName(currentUser.getDisplayName());
|
||||||
|
}
|
||||||
|
joinRoomWithPassword();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupMentionAutocomplete() {
|
private void setupMentionAutocomplete() {
|
||||||
@ -317,8 +358,18 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
password = roomPassword;
|
password = roomPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
ncApi.joinRoom(ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken()), ApiUtils
|
if (TextUtils.isEmpty(baseUrl)) {
|
||||||
.getUrlForRoomParticipants(currentUser.getBaseUrl(), roomToken), password)
|
baseUrl = conversationUser.getBaseUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(conversationUser.getUserId())) {
|
||||||
|
credentials = null;
|
||||||
|
} else {
|
||||||
|
credentials = ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentCall == null) {
|
||||||
|
ncApi.joinRoom(credentials, ApiUtils.getUrlForRoomParticipants(baseUrl, roomToken), password)
|
||||||
.subscribeOn(Schedulers.newThread())
|
.subscribeOn(Schedulers.newThread())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.retry(3)
|
.retry(3)
|
||||||
@ -331,6 +382,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
@Override
|
@Override
|
||||||
public void onNext(CallOverall callOverall) {
|
public void onNext(CallOverall callOverall) {
|
||||||
inChat = true;
|
inChat = true;
|
||||||
|
startPing();
|
||||||
pullChatMessages(0);
|
pullChatMessages(0);
|
||||||
currentCall = callOverall.getOcs().getData();
|
currentCall = callOverall.getOcs().getData();
|
||||||
}
|
}
|
||||||
@ -345,16 +397,21 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
inChat = true;
|
||||||
|
startPing();
|
||||||
|
pullChatMessages(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(String message) {
|
private void sendMessage(String message) {
|
||||||
Map<String, String> fieldMap = new HashMap<>();
|
Map<String, String> fieldMap = new HashMap<>();
|
||||||
fieldMap.put("message", message);
|
fieldMap.put("message", message);
|
||||||
fieldMap.put("actorDisplayName", currentUser.getDisplayName());
|
fieldMap.put("actorDisplayName", conversationUser.getDisplayName());
|
||||||
|
|
||||||
|
|
||||||
ncApi.sendChatMessage(ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken()),
|
ncApi.sendChatMessage(ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken()),
|
||||||
ApiUtils.getUrlForChat(currentUser.getBaseUrl(), roomToken), fieldMap)
|
ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap)
|
||||||
.subscribeOn(Schedulers.newThread())
|
.subscribeOn(Schedulers.newThread())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.retry(3, observable -> inChat)
|
.retry(3, observable -> inChat)
|
||||||
@ -385,6 +442,35 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startPing() {
|
||||||
|
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken))
|
||||||
|
.subscribeOn(Schedulers.newThread())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
|
||||||
|
.takeWhile(observable -> inChat)
|
||||||
|
.retry(3, observable -> inChat)
|
||||||
|
.subscribe(new Observer<GenericOverall>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
disposableList.add(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(GenericOverall genericOverall) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void pullChatMessages(int lookIntoFuture) {
|
private void pullChatMessages(int lookIntoFuture) {
|
||||||
if (!lookingIntoFuture && lookIntoFuture == 1) {
|
if (!lookingIntoFuture && lookIntoFuture == 1) {
|
||||||
lookingIntoFuture = true;
|
lookingIntoFuture = true;
|
||||||
@ -406,8 +492,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lookIntoFuture == 1) {
|
if (lookIntoFuture == 1) {
|
||||||
ncApi.pullChatMessages(ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken()),
|
ncApi.pullChatMessages(ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken()),
|
||||||
ApiUtils.getUrlForChat(currentUser.getBaseUrl(), roomToken), fieldMap)
|
ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap)
|
||||||
.subscribeOn(Schedulers.newThread())
|
.subscribeOn(Schedulers.newThread())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.takeWhile(observable -> inChat)
|
.takeWhile(observable -> inChat)
|
||||||
@ -435,8 +521,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ncApi.pullChatMessages(ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken()),
|
ncApi.pullChatMessages(ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken()),
|
||||||
ApiUtils.getUrlForChat(currentUser.getBaseUrl(), roomToken), fieldMap)
|
ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap)
|
||||||
.subscribeOn(Schedulers.newThread())
|
.subscribeOn(Schedulers.newThread())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.retry(3, observable -> inChat)
|
.retry(3, observable -> inChat)
|
||||||
@ -471,7 +557,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
if (!isFromTheFuture) {
|
if (!isFromTheFuture) {
|
||||||
for (int i = 0; i < chatMessageList.size(); i++) {
|
for (int i = 0; i < chatMessageList.size(); i++) {
|
||||||
chatMessageList.get(i).setBaseUrl(currentUser.getBaseUrl());
|
chatMessageList.get(i).setBaseUrl(conversationUser.getBaseUrl());
|
||||||
if (globalLastKnownPastMessageId == -1 || chatMessageList.get(i).getJsonMessageId() <
|
if (globalLastKnownPastMessageId == -1 || chatMessageList.get(i).getJsonMessageId() <
|
||||||
globalLastKnownPastMessageId) {
|
globalLastKnownPastMessageId) {
|
||||||
globalLastKnownPastMessageId = chatMessageList.get(i).getJsonMessageId();
|
globalLastKnownPastMessageId = chatMessageList.get(i).getJsonMessageId();
|
||||||
@ -488,7 +574,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < chatMessageList.size(); i++) {
|
for (int i = 0; i < chatMessageList.size(); i++) {
|
||||||
chatMessageList.get(i).setBaseUrl(currentUser.getBaseUrl());
|
chatMessageList.get(i).setBaseUrl(conversationUser.getBaseUrl());
|
||||||
boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 ||
|
boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 ||
|
||||||
adapter.getItemCount() == 0;
|
adapter.getItemCount() == 0;
|
||||||
|
|
||||||
@ -548,7 +634,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
inflater.inflate(R.menu.menu_conversation, menu);
|
inflater.inflate(R.menu.menu_conversation, menu);
|
||||||
globalMenu = menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -582,7 +667,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
if (currentCall != null && !TextUtils.isEmpty(currentCall.getSessionId())) {
|
if (currentCall != null && !TextUtils.isEmpty(currentCall.getSessionId())) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
|
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
|
||||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser));
|
||||||
bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId());
|
bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId());
|
||||||
|
|
||||||
if (isVoiceOnlyCall) {
|
if (isVoiceOnlyCall) {
|
||||||
|
@ -129,7 +129,7 @@ public class EntryMenuController extends BaseController {
|
|||||||
bundle = new Bundle();
|
bundle = new Bundle();
|
||||||
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
|
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
|
||||||
bundle.putString(BundleKeys.KEY_CALL_URL, callUrl);
|
bundle.putString(BundleKeys.KEY_CALL_URL, callUrl);
|
||||||
bundle.putString(BundleKeys.KEY_CALL_PASSWORD, editText.getText().toString());
|
bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, editText.getText().toString());
|
||||||
bundle.putInt(BundleKeys.KEY_OPERATION_CODE, operationCode);
|
bundle.putInt(BundleKeys.KEY_OPERATION_CODE, operationCode);
|
||||||
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle))
|
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle))
|
||||||
.pushChangeHandler(new HorizontalChangeHandler())
|
.pushChangeHandler(new HorizontalChangeHandler())
|
||||||
|
@ -125,7 +125,7 @@ public class OperationsMenuController extends BaseController {
|
|||||||
this.room = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM));
|
this.room = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.callPassword = args.getString(BundleKeys.KEY_CALL_PASSWORD, "");
|
this.callPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
|
||||||
this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, "");
|
this.callUrl = args.getString(BundleKeys.KEY_CALL_URL, "");
|
||||||
|
|
||||||
if (args.containsKey(BundleKeys.KEY_INVITED_PARTICIPANTS)) {
|
if (args.containsKey(BundleKeys.KEY_INVITED_PARTICIPANTS)) {
|
||||||
|
@ -32,12 +32,11 @@ public class BundleKeys {
|
|||||||
public static final String KEY_SHARE_INTENT = "KEY_SHARE_INTENT";
|
public static final String KEY_SHARE_INTENT = "KEY_SHARE_INTENT";
|
||||||
public static final String KEY_APP_ITEM_PACKAGE_NAME = "KEY_APP_ITEM_PACKAGE_NAME";
|
public static final String KEY_APP_ITEM_PACKAGE_NAME = "KEY_APP_ITEM_PACKAGE_NAME";
|
||||||
public static final String KEY_APP_ITEM_NAME = "KEY_APP_ITEM_NAME";
|
public static final String KEY_APP_ITEM_NAME = "KEY_APP_ITEM_NAME";
|
||||||
public static final String KEY_CALL_PASSWORD = "KEY_CONVERSATION_PASSWORD";
|
public static final String KEY_CONVERSATION_PASSWORD = "KEY_CONVERSATION_PASSWORD";
|
||||||
public static final String KEY_CALL_SESSION = "KEY_CONVERSATION_SESSION";
|
public static final String KEY_CALL_SESSION = "KEY_CONVERSATION_SESSION";
|
||||||
public static final String KEY_ROOM_TOKEN = "KEY_ROOM_TOKEN";
|
public static final String KEY_ROOM_TOKEN = "KEY_ROOM_TOKEN";
|
||||||
public static final String KEY_USER_ENTITY = "KEY_USER_ENTITY";
|
public static final String KEY_USER_ENTITY = "KEY_USER_ENTITY";
|
||||||
public static final String KEY_NEW_CONVERSATION = "KEY_NEW_CONVERSATION";
|
public static final String KEY_NEW_CONVERSATION = "KEY_NEW_CONVERSATION";
|
||||||
public static final String KEY_IS_PUBLIC_CALL = "KEY_IS_PUBLIC_CALL";
|
|
||||||
public static final String KEY_CALL_URL = "KEY_CALL_URL";
|
public static final String KEY_CALL_URL = "KEY_CALL_URL";
|
||||||
public static final String KEY_MODIFIED_BASE_URL = "KEY_MODIFIED_BASE_URL";
|
public static final String KEY_MODIFIED_BASE_URL = "KEY_MODIFIED_BASE_URL";
|
||||||
public static final String KEY_NOTIFICATION_SUBJECT = "KEY_NOTIFICATION_SUBJECT";
|
public static final String KEY_NOTIFICATION_SUBJECT = "KEY_NOTIFICATION_SUBJECT";
|
||||||
@ -46,6 +45,6 @@ public class BundleKeys {
|
|||||||
public static final String KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE";
|
public static final String KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE";
|
||||||
public static final String KEY_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS";
|
public static final String KEY_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS";
|
||||||
public static final String KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME";
|
public static final String KEY_CONVERSATION_NAME = "KEY_CONVERSATION_NAME";
|
||||||
public static final String KEY_ROOM_PASSWORD = "KEY_ROOM_PASSWORD";
|
|
||||||
public static final String KEY_CALL_VOICE_ONLY = "KEY_CALL_VOICE_ONLY";
|
public static final String KEY_CALL_VOICE_ONLY = "KEY_CALL_VOICE_ONLY";
|
||||||
|
public static final String KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user