Fix some of the guest-related issues

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-02-14 04:10:10 +01:00
parent 68c45f6831
commit 3a07193c3b
5 changed files with 41 additions and 55 deletions

View File

@ -135,14 +135,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
private UserEntity conversationUser; private UserEntity conversationUser;
private String roomPassword; private String roomPassword;
private String credentials; 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 CharSequence myFirstMessage;
private Autocomplete mentionAutocomplete; private Autocomplete mentionAutocomplete;
private LinearLayoutManager layoutManager; private LinearLayoutManager layoutManager;
private boolean lookingIntoFuture = false; private boolean lookingIntoFuture = false;
@ -164,14 +162,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
setHasOptionsMenu(true); setHasOptionsMenu(true);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
UserEntity currentUser = userUtils.getCurrentUser();
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, ""); this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, "");
if (args.containsKey(BundleKeys.KEY_USER_ENTITY)) { this.conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY);
this.conversationUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY));
} else {
this.conversationUser = currentUser;
}
this.roomId = args.getString(BundleKeys.KEY_ROOM_ID, ""); this.roomId = args.getString(BundleKeys.KEY_ROOM_ID, "");
this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN, ""); this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN, "");
@ -179,16 +171,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
this.currentCall = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION)); this.currentCall = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION));
} }
this.baseUrl = args.getString(BundleKeys.KEY_MODIFIED_BASE_URL, "");
if (!TextUtils.isEmpty(baseUrl)) {
conversationUser.setBaseUrl(baseUrl);
conversationUser.setUserId("?");
conversationUser.setDisplayName(currentUser.getDisplayName());
} else {
baseUrl = conversationUser.getBaseUrl();
}
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, ""); this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
if (conversationUser.getUserId().equals("?")) { if (conversationUser.getUserId().equals("?")) {
@ -205,7 +187,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
private void getRoomInfo() { private void getRoomInfo() {
ncApi.getRoom(credentials, ApiUtils.getRoom(baseUrl, roomToken)) ncApi.getRoom(credentials, ApiUtils.getRoom(conversationUser.getBaseUrl(), roomToken))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RoomOverall>() { .subscribe(new Observer<RoomOverall>() {
@ -238,7 +220,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
private void handleFromNotification() { private void handleFromNotification() {
ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(baseUrl)) ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(conversationUser.getBaseUrl()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RoomsOverall>() { .subscribe(new Observer<RoomsOverall>() {
@ -424,7 +406,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
private void showConversationInfoScreen() { private void showConversationInfoScreen() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser)); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser));
bundle.putString(BundleKeys.KEY_BASE_URL, baseUrl); bundle.putString(BundleKeys.KEY_BASE_URL, conversationUser.getBaseUrl());
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle)) getRouter().pushController((RouterTransaction.with(new ConversationInfoController(bundle))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
@ -503,6 +485,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override @Override
protected void onDetach(@NonNull View view) { protected void onDetach(@NonNull View view) {
super.onDetach(view); super.onDetach(view);
ApplicationWideCurrentRoomHolder.getInstance().clear();
if (conversationUser.hasSpreedCapabilityWithName("no-ping") if (conversationUser.hasSpreedCapabilityWithName("no-ping")
&& getActivity() != null && !getActivity().isChangingConfigurations() && !isLeavingForConversation) { && getActivity() != null && !getActivity().isChangingConfigurations() && !isLeavingForConversation) {
wasDetached = true; wasDetached = true;
@ -525,7 +509,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
adapter = null; adapter = null;
inChat = false; inChat = false;
ApplicationWideCurrentRoomHolder.getInstance().clear();
} }
private void dispose() { private void dispose() {
@ -539,7 +522,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
private void startPing() { private void startPing() {
if (!conversationUser.hasSpreedCapabilityWithName("no-ping")) { if (!conversationUser.hasSpreedCapabilityWithName("no-ping")) {
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken)) ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(conversationUser.getBaseUrl(), roomToken))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS)) .repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
@ -583,7 +566,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
private void joinRoomWithPassword() { private void joinRoomWithPassword() {
if (currentCall == null) { if (currentCall == null) {
ncApi.joinRoom(credentials, ApiUtils.getUrlForSettingMyselfAsActiveParticipant(baseUrl, roomToken), roomPassword) ncApi.joinRoom(credentials,
ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser.getBaseUrl(), roomToken), roomPassword)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(3) .retry(3)
@ -633,7 +617,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
private void leaveRoom() { private void leaveRoom() {
ncApi.leaveRoom(credentials, ApiUtils.getUrlForSettingMyselfAsActiveParticipant(baseUrl, roomToken)) ncApi.leaveRoom(credentials,
ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser.getBaseUrl(),
roomToken))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<GenericOverall>() { .subscribe(new Observer<GenericOverall>() {
@ -668,15 +654,16 @@ public class ChatController extends BaseController implements MessagesListAdapte
senderId.setAccessible(true); senderId.setAccessible(true);
senderId.set(adapter, conversationUser.getUserId()); senderId.set(adapter, conversationUser.getUserId());
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
Log.e(TAG, "Failed to set sender id"); Log.w(TAG, "Failed to set sender id");
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
Log.e(TAG, "Failed to access and set field"); Log.w(TAG, "Failed to access and set field");
} }
} }
private void sendMessage(CharSequence message) { private void sendMessage(CharSequence message) {
ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(baseUrl, roomToken), message, conversationUser ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken),
message, conversationUser
.getDisplayName()) .getDisplayName())
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -688,10 +675,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override @Override
public void onNext(GenericOverall genericOverall) { public void onNext(GenericOverall genericOverall) {
if (conversationUser.getUserId().equals("?") && TextUtils.isEmpty(myFirstMessage.toString())) {
myFirstMessage = message;
}
if (popupBubble != null && popupBubble.isShown()) { if (popupBubble != null && popupBubble.isShown()) {
popupBubble.hide(); popupBubble.hide();
} }
@ -706,10 +689,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (e instanceof HttpException) { if (e instanceof HttpException) {
int code = ((HttpException) e).code(); int code = ((HttpException) e).code();
if (Integer.toString(code).startsWith("2")) { if (Integer.toString(code).startsWith("2")) {
if (conversationUser.getUserId().equals("?") && TextUtils.isEmpty(myFirstMessage.toString())) {
myFirstMessage = message;
}
if (popupBubble != null && popupBubble.isShown()) { if (popupBubble != null && popupBubble.isShown()) {
popupBubble.hide(); popupBubble.hide();
} }
@ -752,7 +731,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (!wasDetached) { if (!wasDetached) {
if (lookIntoFuture == 1) { if (lookIntoFuture == 1) {
ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap) ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(conversationUser.getBaseUrl(),
roomToken),
fieldMap)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.takeWhile(observable -> inChat && !wasDetached) .takeWhile(observable -> inChat && !wasDetached)
@ -781,7 +762,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
} else { } else {
ncApi.pullChatMessages(credentials, ncApi.pullChatMessages(credentials,
ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap) ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(3, observable -> inChat && !wasDetached) .retry(3, observable -> inChat && !wasDetached)
@ -896,14 +877,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
chatMessage.setBaseUrl(conversationUser.getBaseUrl()); chatMessage.setBaseUrl(conversationUser.getBaseUrl());
chatMessageList.get(i).setActiveUserId(conversationUser.getUserId()); chatMessageList.get(i).setActiveUserId(conversationUser.getUserId());
if (conversationUser.getUserId().equals("?") && myFirstMessage != null &&
!TextUtils.isEmpty(myFirstMessage.toString())) {
if (chatMessage.getActorType().equals("guests") &&
chatMessage.getActorDisplayName().equals(conversationUser.getDisplayName())) {
conversationUser.setUserId(chatMessage.getActorId());
setSenderId();
}
}
boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 || boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 ||
(adapter != null && adapter.getItemCount() == 0); (adapter != null && adapter.getItemCount() == 0);
@ -1024,7 +997,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
bundle.putString(BundleKeys.KEY_ROOM_ID, roomId); bundle.putString(BundleKeys.KEY_ROOM_ID, roomId);
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser)); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser));
bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword); bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword);
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, conversationUser.getBaseUrl());
if (isVoiceOnlyCall) { if (isVoiceOnlyCall) {
bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true); bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true);

View File

@ -281,6 +281,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
public void onNext(RoomOverall roomOverall) { public void onNext(RoomOverall roomOverall) {
Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class); Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId()); bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
@ -888,6 +889,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
if (getActivity() != null) { if (getActivity() != null) {
Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class); Intent conversationIntent = new Intent(getActivity(), MagicCallActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId()); bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);

View File

@ -301,8 +301,10 @@ public class ConversationInfoController extends BaseController {
setProperNotificationValue(conversation); setProperNotificationValue(conversation);
} }
} else { } else {
messageNotificationLevel.setEnabled(false); if (messageNotificationLevel != null) {
messageNotificationLevel.setAlpha(0.38f); messageNotificationLevel.setEnabled(false);
messageNotificationLevel.setAlpha(0.38f);
}
setProperNotificationValue(conversation); setProperNotificationValue(conversation);
} }

View File

@ -581,9 +581,9 @@ public class ConversationsListController extends BaseController implements Searc
} }
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.getRoomId()); bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.getRoomId());
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken());
if (conversation.hasPassword && (conversation.participantType.equals(Participant.ParticipantType.GUEST) || if (conversation.hasPassword && (conversation.participantType.equals(Participant.ParticipantType.GUEST) ||
conversation.participantType.equals(Participant.ParticipantType.USER_FOLLOWING_LINK))) { conversation.participantType.equals(Participant.ParticipantType.USER_FOLLOWING_LINK))) {

View File

@ -482,8 +482,7 @@ public class OperationsMenuController extends BaseController {
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new HorizontalChangeHandler()));
} else { } else {
initiateConversation(false, capabilitiesOverall.getOcs().getData() initiateConversation(false, capabilitiesOverall.getOcs().getData()
.getCapabilities().getSpreedCapability() .getCapabilities().getSpreedCapability().getFeatures());
.getFeatures());
} }
} else if (capabilitiesOverall.getOcs().getData() } else if (capabilitiesOverall.getOcs().getData()
.getCapabilities().getSpreedCapability() != null && .getCapabilities().getSpreedCapability() != null &&
@ -608,10 +607,11 @@ public class OperationsMenuController extends BaseController {
private void initiateConversation(boolean dismissView, @Nullable List<String> spreedCapabilities) { private void initiateConversation(boolean dismissView, @Nullable List<String> spreedCapabilities) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
boolean isGuestUser = false;
boolean hasChatCapability; boolean hasChatCapability;
if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) { if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl); isGuestUser = true;
hasChatCapability = spreedCapabilities != null && spreedCapabilities.contains("chat-v2"); hasChatCapability = spreedCapabilities != null && spreedCapabilities.contains("chat-v2");
} else { } else {
hasChatCapability = currentUser.hasSpreedCapabilityWithName("chat-v2"); hasChatCapability = currentUser.hasSpreedCapabilityWithName("chat-v2");
@ -626,6 +626,16 @@ public class OperationsMenuController extends BaseController {
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.getRoomId()); bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.getRoomId());
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, conversation.getDisplayName()); bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, conversation.getDisplayName());
UserEntity conversationUser;
if (isGuestUser) {
conversationUser = new UserEntity();
conversationUser.setBaseUrl(baseUrl);
conversationUser.setUserId("?");
} else {
conversationUser = currentUser;
}
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call)); bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call));
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);
@ -635,7 +645,6 @@ public class OperationsMenuController extends BaseController {
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new HorizontalChangeHandler()));
} }
} else { } else {
initiateCall(); initiateCall();
} }