mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 21:15:30 +03:00
Guest chat support + other things
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
711257328e
commit
e6825275ba
5 changed files with 107 additions and 12 deletions
|
@ -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() {
|
||||
ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(baseUrl, roomToken))
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
|
@ -1269,7 +1296,11 @@ public class CallActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onNext(GenericOverall genericOverall) {
|
||||
finish();
|
||||
if (isMultiSession) {
|
||||
finish();
|
||||
} else {
|
||||
leaveRoom();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -92,6 +92,7 @@ import com.webianks.library.PopupBubble;
|
|||
import org.parceler.Parcels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
@ -142,11 +143,14 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
private int globalLastKnownPastMessageId = -1;
|
||||
private MessagesListAdapter<ChatMessage> adapter;
|
||||
|
||||
private String myFirstMessage;
|
||||
|
||||
private Autocomplete mentionAutocomplete;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private boolean lookingIntoFuture = false;
|
||||
|
||||
private int newMessagesCount = 0;
|
||||
private String senderId;
|
||||
|
||||
/*
|
||||
TODO:
|
||||
|
@ -166,6 +170,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
this.currentCall = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION));
|
||||
}
|
||||
this.baseUrl = args.getString(BundleKeys.KEY_MODIFIED_BASE_URL, "");
|
||||
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -180,6 +185,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
|
||||
boolean adapterWasNull = false;
|
||||
|
||||
if (conversationUser != null && conversationUser.getUserId() != null) {
|
||||
senderId = conversationUser.getUserId();
|
||||
} else {
|
||||
senderId = "-1";
|
||||
}
|
||||
|
||||
if (adapter == null) {
|
||||
|
||||
try {
|
||||
|
@ -196,7 +207,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
holdersConfig.setOutcoming(MagicOutcomingTextMessageViewHolder.class,
|
||||
R.layout.item_custom_outcoming_text_message);
|
||||
|
||||
adapter = new MessagesListAdapter<>(conversationUser.getUserId(), holdersConfig, new ImageLoader() {
|
||||
adapter = new MessagesListAdapter<>(senderId, holdersConfig, new ImageLoader() {
|
||||
@Override
|
||||
public void loadImage(ImageView imageView, String url) {
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
|
@ -297,6 +308,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
if (conversationUser == null) {
|
||||
conversationUser = new UserEntity();
|
||||
conversationUser.setDisplayName(currentUser.getDisplayName());
|
||||
conversationUser.setBaseUrl(baseUrl);
|
||||
}
|
||||
joinRoomWithPassword();
|
||||
}
|
||||
|
@ -371,7 +383,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
private void joinRoomWithPassword() {
|
||||
String password = "";
|
||||
|
||||
if (TextUtils.isEmpty(roomPassword)) {
|
||||
if (!TextUtils.isEmpty(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) {
|
||||
Map<String, String> fieldMap = new HashMap<>();
|
||||
fieldMap.put("message", message);
|
||||
|
@ -439,6 +465,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
|
||||
@Override
|
||||
public void onNext(GenericOverall genericOverall) {
|
||||
if (senderId.equals("-1") && TextUtils.isEmpty(myFirstMessage)) {
|
||||
myFirstMessage = message;
|
||||
}
|
||||
|
||||
if (popupBubble.isShown()) {
|
||||
popupBubble.hide();
|
||||
}
|
||||
|
@ -590,6 +620,13 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
} else {
|
||||
for (int i = 0; i < chatMessageList.size(); i++) {
|
||||
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 ||
|
||||
adapter.getItemCount() == 0;
|
||||
|
||||
|
|
|
@ -131,6 +131,9 @@ public class EntryMenuController extends BaseController {
|
|||
bundle.putString(BundleKeys.KEY_CALL_URL, callUrl);
|
||||
bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, editText.getText().toString());
|
||||
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))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -63,6 +64,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||
import org.parceler.Parcels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -117,6 +119,7 @@ public class OperationsMenuController extends BaseController {
|
|||
private Room.RoomType conversationType;
|
||||
private ArrayList<String> invitedUsers = new ArrayList<>();
|
||||
|
||||
private List<String> spreedCapabilities;
|
||||
private String credentials;
|
||||
|
||||
public OperationsMenuController(Bundle args) {
|
||||
|
@ -136,6 +139,10 @@ public class OperationsMenuController extends BaseController {
|
|||
if (args.containsKey(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
|
||||
|
@ -435,12 +442,17 @@ public class OperationsMenuController extends BaseController {
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
|
||||
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);
|
||||
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
} else {
|
||||
initiateConversation(true);
|
||||
initiateConversation(false, capabilitiesOverall.getOcs().getData()
|
||||
.getCapabilities().getSpreedCapability()
|
||||
.getFeatures());
|
||||
}
|
||||
} else if (capabilitiesOverall.getOcs().getData()
|
||||
.getCapabilities().getSpreedCapability() != null &&
|
||||
|
@ -503,7 +515,7 @@ public class OperationsMenuController extends BaseController {
|
|||
}
|
||||
|
||||
if (localInvitedUsers.size() == 0) {
|
||||
initiateConversation(false);
|
||||
initiateConversation(false, null);
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
@ -514,18 +526,29 @@ public class OperationsMenuController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
private void initiateConversation(boolean dismissView) {
|
||||
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
|
||||
private void initiateConversation(boolean dismissView, @Nullable List<String> spreedCapabilities) {
|
||||
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,
|
||||
true, true, dismissView));
|
||||
|
||||
Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken());
|
||||
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName());
|
||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
||||
if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
|
||||
bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, baseUrl);
|
||||
if (!isGuest) {
|
||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
|
||||
}
|
||||
|
||||
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call));
|
||||
|
@ -582,7 +605,7 @@ public class OperationsMenuController extends BaseController {
|
|||
} else {
|
||||
CallOverall callOverall = (CallOverall) o;
|
||||
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_CALL_VOICE_ONLY = "KEY_CALL_VOICE_ONLY";
|
||||
public static final String KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION";
|
||||
public static final String KEY_SPREED_CAPABILITIES = "KEY_SPREED_CAPABILITIES";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue