mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-12 10:32:36 +00:00
Guest chat support + other things
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
711257328e
commit
e6825275ba
@ -1257,6 +1257,33 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void leaveRoom() {
|
||||||
|
ncApi.leaveRoom(credentials, ApiUtils.getRoom(baseUrl, roomToken))
|
||||||
|
.subscribeOn(Schedulers.newThread())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<GenericOverall>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(GenericOverall genericOverall) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void hangupNetworkCalls() {
|
private void hangupNetworkCalls() {
|
||||||
ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(baseUrl, roomToken))
|
ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(baseUrl, roomToken))
|
||||||
.subscribeOn(Schedulers.newThread())
|
.subscribeOn(Schedulers.newThread())
|
||||||
@ -1269,7 +1296,11 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(GenericOverall genericOverall) {
|
public void onNext(GenericOverall genericOverall) {
|
||||||
|
if (isMultiSession) {
|
||||||
finish();
|
finish();
|
||||||
|
} else {
|
||||||
|
leaveRoom();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,6 +92,7 @@ import com.webianks.library.PopupBubble;
|
|||||||
import org.parceler.Parcels;
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -142,11 +143,14 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
private int globalLastKnownPastMessageId = -1;
|
private int globalLastKnownPastMessageId = -1;
|
||||||
private MessagesListAdapter<ChatMessage> adapter;
|
private MessagesListAdapter<ChatMessage> adapter;
|
||||||
|
|
||||||
|
private String myFirstMessage;
|
||||||
|
|
||||||
private Autocomplete mentionAutocomplete;
|
private Autocomplete mentionAutocomplete;
|
||||||
private LinearLayoutManager layoutManager;
|
private LinearLayoutManager layoutManager;
|
||||||
private boolean lookingIntoFuture = false;
|
private boolean lookingIntoFuture = false;
|
||||||
|
|
||||||
private int newMessagesCount = 0;
|
private int newMessagesCount = 0;
|
||||||
|
private String senderId;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
@ -166,6 +170,7 @@ 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, "");
|
this.baseUrl = args.getString(BundleKeys.KEY_MODIFIED_BASE_URL, "");
|
||||||
|
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -180,6 +185,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
boolean adapterWasNull = false;
|
boolean adapterWasNull = false;
|
||||||
|
|
||||||
|
if (conversationUser != null && conversationUser.getUserId() != null) {
|
||||||
|
senderId = conversationUser.getUserId();
|
||||||
|
} else {
|
||||||
|
senderId = "-1";
|
||||||
|
}
|
||||||
|
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -196,7 +207,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<>(conversationUser.getUserId(), holdersConfig, new ImageLoader() {
|
adapter = new MessagesListAdapter<>(senderId, 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())
|
||||||
@ -297,6 +308,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
if (conversationUser == null) {
|
if (conversationUser == null) {
|
||||||
conversationUser = new UserEntity();
|
conversationUser = new UserEntity();
|
||||||
conversationUser.setDisplayName(currentUser.getDisplayName());
|
conversationUser.setDisplayName(currentUser.getDisplayName());
|
||||||
|
conversationUser.setBaseUrl(baseUrl);
|
||||||
}
|
}
|
||||||
joinRoomWithPassword();
|
joinRoomWithPassword();
|
||||||
}
|
}
|
||||||
@ -371,7 +383,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
private void joinRoomWithPassword() {
|
private void joinRoomWithPassword() {
|
||||||
String password = "";
|
String password = "";
|
||||||
|
|
||||||
if (TextUtils.isEmpty(roomPassword)) {
|
if (!TextUtils.isEmpty(roomPassword)) {
|
||||||
password = roomPassword;
|
password = roomPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,6 +433,20 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setSenderId(String guestSenderId) {
|
||||||
|
if (senderId.equals("-1")) {
|
||||||
|
try {
|
||||||
|
final Field senderId = adapter.getClass().getDeclaredField("senderId");
|
||||||
|
senderId.setAccessible(true);
|
||||||
|
senderId.set(adapter, guestSenderId);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
Log.e(TAG, "Failed to set sender id");
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.e(TAG, "Failed to access and set field");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@ -439,6 +465,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(GenericOverall genericOverall) {
|
public void onNext(GenericOverall genericOverall) {
|
||||||
|
if (senderId.equals("-1") && TextUtils.isEmpty(myFirstMessage)) {
|
||||||
|
myFirstMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
if (popupBubble.isShown()) {
|
if (popupBubble.isShown()) {
|
||||||
popupBubble.hide();
|
popupBubble.hide();
|
||||||
}
|
}
|
||||||
@ -590,6 +620,13 @@ 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(conversationUser.getBaseUrl());
|
chatMessageList.get(i).setBaseUrl(conversationUser.getBaseUrl());
|
||||||
|
if (senderId.equals("-1") && !TextUtils.isEmpty(myFirstMessage)) {
|
||||||
|
ChatMessage chatMessage = chatMessageList.get(i);
|
||||||
|
if (chatMessage.getActorType().equals("guests") &&
|
||||||
|
chatMessage.getActorDisplayName().equals(conversationUser.getDisplayName())) {
|
||||||
|
setSenderId(chatMessage.getActorId());
|
||||||
|
}
|
||||||
|
}
|
||||||
boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 ||
|
boolean shouldScroll = layoutManager.findFirstVisibleItemPosition() == 0 ||
|
||||||
adapter.getItemCount() == 0;
|
adapter.getItemCount() == 0;
|
||||||
|
|
||||||
|
@ -131,6 +131,9 @@ public class EntryMenuController extends BaseController {
|
|||||||
bundle.putString(BundleKeys.KEY_CALL_URL, callUrl);
|
bundle.putString(BundleKeys.KEY_CALL_URL, callUrl);
|
||||||
bundle.putString(BundleKeys.KEY_CONVERSATION_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);
|
||||||
|
if(originalBundle.containsKey(BundleKeys.KEY_SPREED_CAPABILITIES)) {
|
||||||
|
bundle.putParcelable(BundleKeys.KEY_SPREED_CAPABILITIES, originalBundle.getParcelable(BundleKeys.KEY_SPREED_CAPABILITIES));
|
||||||
|
}
|
||||||
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle))
|
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle))
|
||||||
.pushChangeHandler(new HorizontalChangeHandler())
|
.pushChangeHandler(new HorizontalChangeHandler())
|
||||||
.popChangeHandler(new HorizontalChangeHandler()));
|
.popChangeHandler(new HorizontalChangeHandler()));
|
||||||
|
@ -25,6 +25,7 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -63,6 +64,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
import org.parceler.Parcels;
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -117,6 +119,7 @@ public class OperationsMenuController extends BaseController {
|
|||||||
private Room.RoomType conversationType;
|
private Room.RoomType conversationType;
|
||||||
private ArrayList<String> invitedUsers = new ArrayList<>();
|
private ArrayList<String> invitedUsers = new ArrayList<>();
|
||||||
|
|
||||||
|
private List<String> spreedCapabilities;
|
||||||
private String credentials;
|
private String credentials;
|
||||||
|
|
||||||
public OperationsMenuController(Bundle args) {
|
public OperationsMenuController(Bundle args) {
|
||||||
@ -136,6 +139,10 @@ public class OperationsMenuController extends BaseController {
|
|||||||
if (args.containsKey(BundleKeys.KEY_CONVERSATION_TYPE)) {
|
if (args.containsKey(BundleKeys.KEY_CONVERSATION_TYPE)) {
|
||||||
this.conversationType = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_CONVERSATION_TYPE));
|
this.conversationType = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_CONVERSATION_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.containsKey(BundleKeys.KEY_SPREED_CAPABILITIES)) {
|
||||||
|
this.spreedCapabilities = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_SPREED_CAPABILITIES));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -435,12 +442,17 @@ public class OperationsMenuController extends BaseController {
|
|||||||
Bundle bundle = new Bundle();
|
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.putParcelable(BundleKeys.KEY_SPREED_CAPABILITIES,
|
||||||
|
Parcels.wrap(capabilitiesOverall.getOcs().getData().getCapabilities()
|
||||||
|
.getSpreedCapability().getFeatures()));
|
||||||
bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 99);
|
bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 99);
|
||||||
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
||||||
.pushChangeHandler(new HorizontalChangeHandler())
|
.pushChangeHandler(new HorizontalChangeHandler())
|
||||||
.popChangeHandler(new HorizontalChangeHandler()));
|
.popChangeHandler(new HorizontalChangeHandler()));
|
||||||
} else {
|
} else {
|
||||||
initiateConversation(true);
|
initiateConversation(false, capabilitiesOverall.getOcs().getData()
|
||||||
|
.getCapabilities().getSpreedCapability()
|
||||||
|
.getFeatures());
|
||||||
}
|
}
|
||||||
} else if (capabilitiesOverall.getOcs().getData()
|
} else if (capabilitiesOverall.getOcs().getData()
|
||||||
.getCapabilities().getSpreedCapability() != null &&
|
.getCapabilities().getSpreedCapability() != null &&
|
||||||
@ -503,7 +515,7 @@ public class OperationsMenuController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (localInvitedUsers.size() == 0) {
|
if (localInvitedUsers.size() == 0) {
|
||||||
initiateConversation(false);
|
initiateConversation(false, null);
|
||||||
}
|
}
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
@ -514,18 +526,29 @@ public class OperationsMenuController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initiateConversation(boolean dismissView) {
|
private void initiateConversation(boolean dismissView, @Nullable List<String> spreedCapabilities) {
|
||||||
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
|
Bundle bundle = new Bundle();
|
||||||
|
boolean hasChatCapability;
|
||||||
|
boolean isGuest = false;
|
||||||
|
|
||||||
|
if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
|
||||||
|
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl);
|
||||||
|
hasChatCapability = spreedCapabilities != null && spreedCapabilities.contains("chat-v2");
|
||||||
|
isGuest = true;
|
||||||
|
} else {
|
||||||
|
hasChatCapability = currentUser.hasSpreedCapabilityWithName("chat-v2");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (hasChatCapability) {
|
||||||
eventBus.post(new BottomSheetLockEvent(true, 0,
|
eventBus.post(new BottomSheetLockEvent(true, 0,
|
||||||
true, true, dismissView));
|
true, true, dismissView));
|
||||||
|
|
||||||
Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
|
Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken());
|
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken());
|
||||||
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName());
|
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName());
|
||||||
|
if (!isGuest) {
|
||||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
||||||
if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
|
|
||||||
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call));
|
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call));
|
||||||
@ -582,7 +605,7 @@ public class OperationsMenuController extends BaseController {
|
|||||||
} else {
|
} else {
|
||||||
CallOverall callOverall = (CallOverall) o;
|
CallOverall callOverall = (CallOverall) o;
|
||||||
call = callOverall.getOcs().getData();
|
call = callOverall.getOcs().getData();
|
||||||
initiateConversation(true);
|
initiateConversation(true, spreedCapabilities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,4 +47,5 @@ public class BundleKeys {
|
|||||||
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_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";
|
public static final String KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION";
|
||||||
|
public static final String KEY_SPREED_CAPABILITIES = "KEY_SPREED_CAPABILITIES";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user