Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-07-05 09:40:16 +02:00
parent 010850b67a
commit 48a011bbdb
14 changed files with 68 additions and 42 deletions

View file

@ -1120,7 +1120,7 @@ public class CallController extends BaseController {
urlToken = roomToken;
}
if (!conversationUser.hasSpreedCapabilityWithName("no-ping") && !TextUtils.isEmpty(roomId)) {
if (!conversationUser.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) {
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomId);
} else if (!TextUtils.isEmpty(roomToken)) {
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomToken);

View file

@ -26,7 +26,6 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.net.Uri;
@ -57,7 +56,6 @@ import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.postprocessors.BlurPostProcessor;
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
import com.facebook.imagepipeline.request.ImageRequest;
import com.nextcloud.talk.R;
import com.nextcloud.talk.api.NcApi;
@ -428,7 +426,7 @@ public class CallNotificationController extends BaseController {
}
if ((AvatarStatusCodeHolder.getInstance().getStatusCode() == 200 || AvatarStatusCodeHolder.getInstance().getStatusCode() == 0) &&
userBeingCalled.hasSpreedCapabilityWithName("no-ping")) {
userBeingCalled.hasSpreedFeatureCapability("no-ping")) {
if (getActivity() != null) {
Bitmap backgroundBitmap = bitmap.copy(bitmap.getConfig(), true);
new BlurPostProcessor(5, getActivity()).process(backgroundBitmap);

View file

@ -368,7 +368,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(1000);
int lenghtFilter = conversationUser.getMessageMaxLength();
filters[0] = new InputFilter.LengthFilter(lenghtFilter);
messageInput.setFilters(filters);
messageInput.addTextChangedListener(new TextWatcher() {
@ -379,8 +382,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() == 1000) {
messageInput.setError(Objects.requireNonNull(getResources()).getString(R.string.nc_limit_hit));
if (s.length() >= lenghtFilter) {
messageInput.setError(String.format(Objects.requireNonNull(getResources()).getString(R.string.nc_limit_hit), Integer.toString(lenghtFilter)));
} else {
messageInput.setError(null);
}
@ -417,7 +420,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
messageInputView.getButton().setContentDescription(getResources()
.getString(R.string.nc_description_send_message_button));
if (!conversationUser.getUserId().equals("?") && conversationUser.hasSpreedCapabilityWithName("mention-flag") && getActivity() != null) {
if (!conversationUser.getUserId().equals("?") && conversationUser.hasSpreedFeatureCapability("mention-flag") && getActivity() != null) {
getActivity().findViewById(R.id.toolbar).setOnClickListener(v -> showConversationInfoScreen());
}
@ -557,7 +560,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
cancelNotificationsForCurrentConversation();
if (inChat) {
if (wasDetached && conversationUser.hasSpreedCapabilityWithName("no-ping")) {
if (wasDetached && conversationUser.hasSpreedFeatureCapability("no-ping")) {
wasDetached = false;
joinRoomWithPassword();
}
@ -565,7 +568,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
private void cancelNotificationsForCurrentConversation() {
if (!conversationUser.hasSpreedCapabilityWithName("no-ping") && !TextUtils.isEmpty(roomId)) {
if (!conversationUser.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) {
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomId);
} else if (!TextUtils.isEmpty(roomToken)){
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomToken);
@ -578,7 +581,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
ApplicationWideCurrentRoomHolder.getInstance().clear();
eventBus.unregister(this);
if (conversationUser.hasSpreedCapabilityWithName("no-ping")
if (conversationUser.hasSpreedFeatureCapability("no-ping")
&& getActivity() != null && !getActivity().isChangingConfigurations() && !isLeavingForConversation) {
wasDetached = true;
leaveRoom();
@ -616,7 +619,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
private void startPing() {
if (!conversationUser.hasSpreedCapabilityWithName("no-ping")) {
if (!conversationUser.hasSpreedFeatureCapability("no-ping")) {
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(conversationUser.getBaseUrl(), roomToken))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -1058,7 +1061,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
if (conversationUser.hasSpreedCapabilityWithName("read-only-rooms")) {
if (conversationUser.hasSpreedFeatureCapability("read-only-rooms")) {
checkReadOnlyState();
}
}
@ -1179,7 +1182,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
if (conversationUser.hasSpreedCapabilityWithName("chat-v2")) {
if (conversationUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.getOcs().getData()));
conversationIntent.putExtras(bundle);

View file

@ -45,7 +45,6 @@ import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Optional;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.bluelinelabs.logansquare.LoganSquare;
import com.kennyc.bottomsheet.BottomSheet;
@ -264,7 +263,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.getOcs().getData()));
@ -383,7 +382,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
RetrofitBucket retrofitBucket;
boolean serverIs14OrUp = false;
if (currentUser.hasSpreedCapabilityWithName("last-room-activity")) {
if (currentUser.hasSpreedFeatureCapability("last-room-activity")) {
// a hack to see if we're on 14 or not
retrofitBucket = ApiUtils.getRetrofitBucketForContactsSearchFor14(currentUser.getBaseUrl(), query);
serverIs14OrUp = true;
@ -845,7 +844,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
conversationIntent.putExtras(bundle);
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.getOcs().getData()));
@ -886,8 +885,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
}
}
if (currentUser.hasSpreedCapabilityWithName("last-room-activity")
&& !currentUser.hasSpreedCapabilityWithName("invite-groups-and-mails") &&
if (currentUser.hasSpreedFeatureCapability("last-room-activity")
&& !currentUser.hasSpreedFeatureCapability("invite-groups-and-mails") &&
"groups".equals(((UserItem) adapter.getItem(position)).getModel().getSource()) &&
participant.isSelected() &&
adapter.getSelectedItemCount() > 1) {

View file

@ -400,7 +400,7 @@ public class ConversationInfoController extends BaseController {
loadConversationAvatar();
if (conversationUser.hasSpreedCapabilityWithName("notification-levels")) {
if (conversationUser.hasSpreedFeatureCapability("notification-levels")) {
if (messageNotificationLevel != null) {
messageNotificationLevel.setEnabled(true);
messageNotificationLevel.setAlpha(1.0f);
@ -457,7 +457,7 @@ public class ConversationInfoController extends BaseController {
if (messageNotificationLevel != null) {
if (conversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)) {
// hack to see if we get mentioned always or just on mention
if (conversationUser.hasSpreedCapabilityWithName("mention-flag")) {
if (conversationUser.hasSpreedFeatureCapability("mention-flag")) {
messageNotificationLevel.setValue("always");
} else {
messageNotificationLevel.setValue("mention");

View file

@ -24,7 +24,6 @@ import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -60,7 +59,6 @@ import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
import com.facebook.imagepipeline.request.ImageRequest;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.kennyc.bottomsheet.BottomSheet;
@ -246,7 +244,7 @@ public class ConversationsListController extends BaseController implements Searc
if (currentUser != null) {
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
shouldUseLastMessageLayout = currentUser.hasSpreedCapabilityWithName("last-room-activity");
shouldUseLastMessageLayout = currentUser.hasSpreedFeatureCapability("last-room-activity");
fetchData(false);
}
}
@ -361,7 +359,7 @@ public class ConversationsListController extends BaseController implements Searc
}
}
if (currentUser.hasSpreedCapabilityWithName("last-room-activity")) {
if (currentUser.hasSpreedFeatureCapability("last-room-activity")) {
Collections.sort(callItems, (o1, o2) -> {
Conversation conversation1 = ((ConversationItem) o1).getModel();
Conversation conversation2 = ((ConversationItem) o2).getModel();
@ -637,7 +635,7 @@ public class ConversationsListController extends BaseController implements Searc
} else {
currentUser = userUtils.getCurrentUser();
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
if (currentUser.hasSpreedFeatureCapability("chat-v2")) {
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation));
ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
conversation.getToken(), bundle, false);
@ -656,7 +654,7 @@ public class ConversationsListController extends BaseController implements Searc
@Override
public void onItemLongClick(int position) {
if (currentUser.hasSpreedCapabilityWithName("last-room-activity")) {
if (currentUser.hasSpreedFeatureCapability("last-room-activity")) {
Object clickedItem = adapter.getItem(position);
if (clickedItem != null) {
Conversation conversation;

View file

@ -151,7 +151,7 @@ public class CallMenuController extends BaseController implements FlexibleAdapte
if (conversation.isFavorite()) {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_remove_from_favorites), 97, DisplayUtils.getTintedDrawable(getResources(), R.drawable.ic_star_border_black_24dp, R.color.grey_600)));
} else if (currentUser.hasSpreedCapabilityWithName("favorites")) {
} else if (currentUser.hasSpreedFeatureCapability("favorites")) {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_add_to_favorites)
, 98, DisplayUtils.getTintedDrawable(getResources(), R.drawable.ic_star_black_24dp, R.color.grey_600)));
}

View file

@ -46,7 +46,6 @@ import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.MagicCallActivity;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.ChatController;
import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.BottomSheetLockEvent;
import com.nextcloud.talk.models.RetrofitBucket;
@ -269,12 +268,12 @@ public class OperationsMenuController extends BaseController {
}
if (conversationType.equals(Conversation.ConversationType.ROOM_PUBLIC_CALL) ||
!currentUser.hasSpreedCapabilityWithName("empty-group-room")) {
!currentUser.hasSpreedFeatureCapability("empty-group-room")) {
retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(currentUser.getBaseUrl(),
"3", invite, conversationName);
} else {
String roomType = "2";
if (!currentUser.hasSpreedCapabilityWithName("empty-group-room")) {
if (!currentUser.hasSpreedFeatureCapability("empty-group-room")) {
isGroupCallWorkaround = true;
roomType = "3";
}
@ -505,8 +504,8 @@ public class OperationsMenuController extends BaseController {
localInvitedGroups.remove(0);
}
if (localInvitedUsers.size() > 0 || (localInvitedGroups.size() > 0 && currentUser.hasSpreedCapabilityWithName("invite-groups-and-mails"))) {
if ((localInvitedGroups.size() > 0 && currentUser.hasSpreedCapabilityWithName("invite-groups-and-mails"))) {
if (localInvitedUsers.size() > 0 || (localInvitedGroups.size() > 0 && currentUser.hasSpreedFeatureCapability("invite-groups-and-mails"))) {
if ((localInvitedGroups.size() > 0 && currentUser.hasSpreedFeatureCapability("invite-groups-and-mails"))) {
for (int i = 0; i < localInvitedGroups.size(); i++) {
final String groupId = localInvitedGroups.get(i);
retrofitBucket = ApiUtils.getRetrofitBucketForAddGroupParticipant(currentUser.getBaseUrl(), conversation.getToken(),
@ -585,7 +584,7 @@ public class OperationsMenuController extends BaseController {
});
}
} else {
if (!currentUser.hasSpreedCapabilityWithName("chat-v2")) {
if (!currentUser.hasSpreedFeatureCapability("chat-v2")) {
showResultImage(true, false);
} else {
initiateConversation(true, null);
@ -602,7 +601,7 @@ public class OperationsMenuController extends BaseController {
isGuestUser = true;
hasChatCapability = capabilities != null && capabilities.getSpreedCapability() != null && capabilities.getSpreedCapability().getFeatures() != null && capabilities.getSpreedCapability().getFeatures().contains("chat-v2");
} else {
hasChatCapability = currentUser.hasSpreedCapabilityWithName("chat-v2");
hasChatCapability = currentUser.hasSpreedFeatureCapability("chat-v2");
}

View file

@ -442,7 +442,7 @@ public class NotificationWorker extends Worker {
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
boolean hasChatSupport = signatureVerification.getUserEntity().
hasSpreedCapabilityWithName("chat-v2");
hasSpreedFeatureCapability("chat-v2");
boolean shouldShowNotification = decryptedPushMessage.getApp().equals("spreed");
@ -460,7 +460,7 @@ public class NotificationWorker extends Worker {
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (!signatureVerification.getUserEntity().hasSpreedCapabilityWithName
if (!signatureVerification.getUserEntity().hasSpreedFeatureCapability
("no-ping")) {
bundle.putString(BundleKeys.KEY_ROOM_ID, decryptedPushMessage.getId());
} else {

View file

@ -30,6 +30,7 @@ import io.requery.Persistable;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
@Entity
public interface User extends Parcelable, Persistable, Serializable {
@ -89,7 +90,7 @@ public interface User extends Parcelable, Persistable, Serializable {
return false;
}
default boolean hasSpreedCapabilityWithName(String capabilityName) {
default boolean hasSpreedFeatureCapability(String capabilityName) {
if (getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(getCapabilities(), Capabilities.class);
@ -103,4 +104,28 @@ public interface User extends Parcelable, Persistable, Serializable {
}
return false;
}
default int getMessageMaxLength() {
if (getCapabilities() != null) {
Capabilities capabilities = null;
try {
capabilities = LoganSquare.parse(getCapabilities(), Capabilities.class);
if (capabilities != null && capabilities.getSpreedCapability() != null && capabilities.getSpreedCapability().getConfig() != null
&& capabilities.getSpreedCapability().getConfig().containsKey("chat")) {
HashMap<String, String> chatConfigHashMap = capabilities.getSpreedCapability().getConfig().get("chat");
if (chatConfigHashMap != null && chatConfigHashMap.containsKey("max-length")) {
int chatSize = Integer.parseInt(chatConfigHashMap.get("max-length"));
if (chatSize > 0) {
return chatSize;
} else {
return 1000;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return 1000;
}
}

View file

@ -25,6 +25,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
import lombok.Data;
import org.parceler.Parcel;
import java.util.HashMap;
import java.util.List;
@Parcel
@ -33,4 +34,7 @@ import java.util.List;
public class SpreedCapability {
@JsonField(name = "features")
List<String> features;
@JsonField(name = "config")
HashMap<String, HashMap<String, String>> config;
}

View file

@ -97,7 +97,7 @@ public class Conversation {
private boolean isLockedOneToOne(UserEntity conversationUser) {
return (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && conversationUser.hasSpreedCapabilityWithName("locked-one-to-one-rooms"));
return (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && conversationUser.hasSpreedFeatureCapability("locked-one-to-one-rooms"));
}
public boolean canModerate(UserEntity conversationUser) {

View file

@ -69,7 +69,7 @@ public class DatabaseStorageModule implements StorageModule {
if (!key.equals("message_notification_level")) {
arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, value, conversationToken);
} else {
if (conversationUser.hasSpreedCapabilityWithName("notification-levels")) {
if (conversationUser.hasSpreedFeatureCapability("notification-levels")) {
if (!TextUtils.isEmpty(messageNotificationLevel) && !messageNotificationLevel.equals(value)) {
int intValue;
switch (value) {

View file

@ -253,7 +253,7 @@
<string name="nc_hello">Hello</string>
<!-- Other -->
<string name="nc_limit_hit">1000 characters limit has been hit</string>
<string name="nc_limit_hit">%s characters limit has been hit</string>
<string name="nc_groups">Groups</string>
<string name="nc_participants">Participants</string>