Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-03-31 16:37:16 +02:00
parent 7f0131d324
commit ae8ff9d1e5
10 changed files with 148 additions and 13 deletions

View File

@ -301,4 +301,9 @@ public interface NcApi {
@FormUrlEncoded @FormUrlEncoded
@POST @POST
Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level); Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String authorization, @Url String url, @Field("level") int level);
@FormUrlEncoded
@PUT
Observable<GenericOverall> setReadOnlyState(@Header("Authorization") String authorization, @Url String url, @Field("state") int state);
} }

View File

@ -140,6 +140,7 @@ 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 Conversation currentConversation;
private Call currentCall; private Call currentCall;
private boolean inChat = false; private boolean inChat = false;
private boolean historyRead = false; private boolean historyRead = false;
@ -162,18 +163,25 @@ public class ChatController extends BaseController implements MessagesListAdapte
private CharSequence myFirstMessage; private CharSequence myFirstMessage;
private MenuItem conversationInfoMenuItem;
private MenuItem conversationVoiceCallMenuItem;
private MenuItem conversationVideoMenuItem;
private boolean readOnlyCheckPerformed;
public ChatController(Bundle args) { public ChatController(Bundle args) {
super(args); super(args);
setHasOptionsMenu(true); setHasOptionsMenu(true);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, "");
this.conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY); this.conversationUser = args.getParcelable(BundleKeys.KEY_USER_ENTITY);
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, "");
if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) { if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) {
this.currentCall = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION)); this.currentConversation = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION));
if (currentConversation != null) {
conversationName = currentConversation.getDisplayName();
}
} }
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, ""); this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
@ -203,8 +211,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override @Override
public void onNext(RoomOverall roomOverall) { public void onNext(RoomOverall roomOverall) {
currentConversation = roomOverall.getOcs().getData();
conversationName = roomOverall.getOcs().getData().getDisplayName(); conversationName = currentConversation.getDisplayName();
setTitle(); setTitle();
setupMentionAutocomplete(); setupMentionAutocomplete();
@ -239,6 +247,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
for (Conversation conversation : roomsOverall.getOcs().getData()) { for (Conversation conversation : roomsOverall.getOcs().getData()) {
if (roomId.equals(conversation.getRoomId())) { if (roomId.equals(conversation.getRoomId())) {
roomToken = conversation.getToken(); roomToken = conversation.getToken();
currentConversation = conversation;
conversationName = conversation.getDisplayName(); conversationName = conversation.getDisplayName();
setTitle(); setTitle();
break; break;
@ -416,6 +425,53 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
} }
private void checkReadOnlyState() {
if (currentConversation != null && !readOnlyCheckPerformed) {
readOnlyCheckPerformed = true;
if (currentConversation.getConversationReadOnlyState() != null &&
!currentConversation.getConversationReadOnlyState().equals(Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY)) {
messageInput.setHint(R.string.nc_readonly_hint);
conversationVoiceCallMenuItem.getIcon().setAlpha(99);
conversationVoiceCallMenuItem.setEnabled(false);
conversationVideoMenuItem.getIcon().setAlpha(99);
conversationVideoMenuItem.setEnabled(false);
setChildrenState(messageInputView, false);
} else {
messageInput.setHint("");
conversationVoiceCallMenuItem.getIcon().setAlpha(255);
conversationVoiceCallMenuItem.setEnabled(true);
conversationVideoMenuItem.getIcon().setAlpha(255);
conversationVideoMenuItem.setEnabled(true);
setChildrenState(messageInputView, true);
}
}
}
private void setChildrenState(View view, boolean enabled) {
if (view.getId() != R.id.messageSendButton) {
view.setEnabled(enabled);
}
if (enabled) {
view.setAlpha(1.0f);
} else {
view.setAlpha(0.38f);
}
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
setChildrenState(child, enabled);
}
}
}
private void showConversationInfoScreen() { private void showConversationInfoScreen() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -602,6 +658,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
} else { } else {
pullChatMessages(1); pullChatMessages(1);
} }
if (startCallFromNotification != null && startCallFromNotification) { if (startCallFromNotification != null && startCallFromNotification) {
startCallFromNotification = false; startCallFromNotification = false;
startACall(voiceOnly); startACall(voiceOnly);
@ -645,7 +702,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override @Override
public void onNext(GenericOverall genericOverall) { public void onNext(GenericOverall genericOverall) {
dispose(); dispose();
currentCall = null; currentConversation = null;
if (!isDestroyed() && !isBeingDestroyed() && !wasDetached) { if (!isDestroyed() && !isBeingDestroyed() && !wasDetached) {
getRouter().popCurrentController(); getRouter().popCurrentController();
} }
@ -997,7 +1054,13 @@ public class ChatController extends BaseController implements MessagesListAdapte
inflater.inflate(R.menu.menu_conversation, menu); inflater.inflate(R.menu.menu_conversation, menu);
if (conversationUser.getUserId().equals("?")) { if (conversationUser.getUserId().equals("?")) {
menu.removeItem(R.id.conversation_info); menu.removeItem(R.id.conversation_info);
} else {
conversationInfoMenuItem = menu.findItem(R.id.conversation_info);
conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call);
conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call);
} }
checkReadOnlyState();
} }
@ -1037,7 +1100,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
private Intent getIntentForCall(boolean isVoiceOnlyCall) { private Intent getIntentForCall(boolean isVoiceOnlyCall) {
if (currentCall != null) { if (currentConversation != null) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
bundle.putString(BundleKeys.KEY_ROOM_ID, roomId); bundle.putString(BundleKeys.KEY_ROOM_ID, roomId);

View File

@ -275,8 +275,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId()); bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
roomOverall.getOcs().getData().getDisplayName()); Parcels.wrap(roomOverall.getOcs().getData()));
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);
getRouter().replaceTopController((RouterTransaction.with(new ChatController(bundle)) getRouter().replaceTopController((RouterTransaction.with(new ChatController(bundle))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
@ -888,8 +888,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
roomOverall.getOcs().getData().getDisplayName()); Parcels.wrap(roomOverall.getOcs().getData()));
getRouter().replaceTopController((RouterTransaction.with(new ChatController(bundle)) getRouter().replaceTopController((RouterTransaction.with(new ChatController(bundle))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()))); .popChangeHandler(new HorizontalChangeHandler())));

View File

@ -668,7 +668,7 @@ public class ConversationsListController extends BaseController implements Searc
currentUser = userUtils.getCurrentUser(); currentUser = userUtils.getCurrentUser();
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, conversation.getDisplayName()); bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation));
getRouter().pushController((RouterTransaction.with(new ChatController(bundle)) getRouter().pushController((RouterTransaction.with(new ChatController(bundle))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()))); .popChangeHandler(new HorizontalChangeHandler())));

View File

@ -624,7 +624,7 @@ public class OperationsMenuController extends BaseController {
} }
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser);
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call)); bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation));
bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, callPassword); bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, callPassword);
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);

View File

@ -0,0 +1,51 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.converters;
import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter;
import com.nextcloud.talk.models.json.rooms.Conversation;
public class EnumReadOnlyConversationConverter extends IntBasedTypeConverter<Conversation.ConversationReadOnlyState> {
@Override
public Conversation.ConversationReadOnlyState getFromInt(int i) {
switch (i) {
case 0:
return Conversation.ConversationReadOnlyState.CONVERSATION_READ_WRITE;
case 1:
return Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY;
default:
return Conversation.ConversationReadOnlyState.CONVERSATION_READ_WRITE;
}
}
@Override
public int convertToInt(Conversation.ConversationReadOnlyState object) {
switch (object) {
case CONVERSATION_READ_WRITE:
return 0;
case CONVERSATION_READ_ONLY:
return 1;
default:
return 0;
}
}
}

View File

@ -29,6 +29,7 @@ import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.chat.ChatMessage; import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter; import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter;
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter; import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
import com.nextcloud.talk.models.json.converters.EnumReadOnlyConversationConverter;
import com.nextcloud.talk.models.json.converters.EnumRoomTypeConverter; import com.nextcloud.talk.models.json.converters.EnumRoomTypeConverter;
import com.nextcloud.talk.models.json.participants.Participant; import com.nextcloud.talk.models.json.participants.Participant;
import lombok.Data; import lombok.Data;
@ -81,6 +82,9 @@ public class Conversation {
String objectType; String objectType;
@JsonField(name = "notificationLevel", typeConverter = EnumNotificationLevelConverter.class) @JsonField(name = "notificationLevel", typeConverter = EnumNotificationLevelConverter.class)
NotificationLevel notificationLevel; NotificationLevel notificationLevel;
@JsonField(name = "readOnly", typeConverter = EnumReadOnlyConversationConverter.class)
ConversationReadOnlyState conversationReadOnlyState;
public boolean isPublic() { public boolean isPublic() {
return (ConversationType.ROOM_PUBLIC_CALL.equals(type)); return (ConversationType.ROOM_PUBLIC_CALL.equals(type));
@ -129,6 +133,11 @@ public class Conversation {
NEVER NEVER
} }
public enum ConversationReadOnlyState {
CONVERSATION_READ_WRITE,
CONVERSATION_READ_ONLY
}
@Parcel @Parcel
public enum ConversationType { public enum ConversationType {
DUMMY, DUMMY,

View File

@ -232,4 +232,8 @@ public class ApiUtils {
public static String getUrlForNotificationWithId(String baseUrl, String notificationId) { public static String getUrlForNotificationWithId(String baseUrl, String notificationId) {
return baseUrl + ocsApiVersion + "/apps/notifications/api/v2/notifications/" + notificationId; return baseUrl + ocsApiVersion + "/apps/notifications/api/v2/notifications/" + notificationId;
} }
public static String getUrlForReadOnlyState(String baseUrl, String roomToken) {
return baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + roomToken + "/read-only";
}
} }

View File

@ -25,6 +25,7 @@
android:id="@+id/conversation_voice_call" android:id="@+id/conversation_voice_call"
android:icon="@drawable/ic_call_white_24dp" android:icon="@drawable/ic_call_white_24dp"
android:orderInCategory="0" android:orderInCategory="0"
android:enabled="false"
android:title="@string/nc_conversation_menu_voice_call" android:title="@string/nc_conversation_menu_voice_call"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
@ -33,6 +34,7 @@
android:icon="@drawable/ic_videocam_white_24px" android:icon="@drawable/ic_videocam_white_24px"
android:orderInCategory="1" android:orderInCategory="1"
android:title="@string/nc_conversation_menu_video_call" android:title="@string/nc_conversation_menu_video_call"
android:enabled="false"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item <item

View File

@ -259,4 +259,5 @@
<string name="nc_user">User</string> <string name="nc_user">User</string>
<string name="nc_guest">Guest</string> <string name="nc_guest">Guest</string>
<string name="nc_following_link">User following a public link</string> <string name="nc_following_link">User following a public link</string>
<string name="nc_readonly_hint">This conversation is locked</string>
</resources> </resources>