Message search: disable feature if unified search capability not present

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-06-01 17:42:59 +02:00
parent 7bfc3f60f1
commit b097e3aac4
No known key found for this signature in database
GPG key ID: 2585783189A62105
3 changed files with 30 additions and 18 deletions

View file

@ -2502,6 +2502,8 @@ class ChatController(args: Bundle) :
if (CapabilitiesUtil.hasSpreedFeatureCapability(it, "read-only-rooms")) {
checkShowCallButtons()
}
val searchItem = menu.findItem(R.id.conversation_search)
searchItem.isVisible = CapabilitiesUtil.isUnifiedSearchAvailable(it)
}
}

View file

@ -326,7 +326,9 @@ public class ConversationsListController extends BaseController implements Flexi
return;
}
searchHelper = new MessageSearchHelper(unifiedSearchRepository);
if (CapabilitiesUtil.isUnifiedSearchAvailable(currentUser)) {
searchHelper = new MessageSearchHelper(unifiedSearchRepository);
}
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
if (getActivity() != null && getActivity() instanceof MainActivity) {
@ -898,7 +900,9 @@ public class ConversationsListController extends BaseController implements Flexi
clearMessageSearchResults();
adapter.setFilter(filter);
adapter.filterItems();
startMessageSearch(filter);
if (CapabilitiesUtil.isUnifiedSearchAvailable(currentUser)) {
startMessageSearch(filter);
}
} else {
resetSearchResults();
}

View file

@ -30,6 +30,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public abstract class CapabilitiesUtil {
@ -38,7 +39,7 @@ public abstract class CapabilitiesUtil {
public static boolean hasNotificationsCapability(@Nullable UserEntity user, String capabilityName) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities.getNotificationsCapability() != null &&
capabilities.getNotificationsCapability().getFeatures() != null) {
return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
@ -53,7 +54,7 @@ public abstract class CapabilitiesUtil {
public static boolean hasExternalCapability(@Nullable UserEntity user, String capabilityName) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities.getExternalCapability() != null &&
capabilities.getExternalCapability().containsKey("v1")) {
return capabilities.getExternalCapability().get("v1").contains(capabilityName);
@ -82,7 +83,7 @@ public abstract class CapabilitiesUtil {
public static boolean hasSpreedFeatureCapability(@Nullable UserEntity user, String capabilityName) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null && capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getFeatures() != null) {
return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
@ -97,7 +98,7 @@ public abstract class CapabilitiesUtil {
public static Integer getMessageMaxLength(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getConfig() != null &&
@ -125,7 +126,7 @@ public abstract class CapabilitiesUtil {
public static boolean isPhoneBookIntegrationAvailable(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
return capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getFeatures() != null &&
@ -140,7 +141,7 @@ public abstract class CapabilitiesUtil {
public static boolean isReadStatusAvailable(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getConfig() != null &&
@ -158,7 +159,7 @@ public abstract class CapabilitiesUtil {
public static boolean isReadStatusPrivate(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getConfig() != null &&
@ -178,7 +179,7 @@ public abstract class CapabilitiesUtil {
public static boolean isUserStatusAvailable(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities.getUserStatusCapability() != null &&
capabilities.getUserStatusCapability().getEnabled() &&
capabilities.getUserStatusCapability().getSupportsEmoji()) {
@ -194,7 +195,7 @@ public abstract class CapabilitiesUtil {
public static String getAttachmentFolder(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getConfig() != null &&
@ -213,9 +214,8 @@ public abstract class CapabilitiesUtil {
public static String getServerName(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
Capabilities capabilities;
try {
capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null && capabilities.getThemingCapability() != null) {
return capabilities.getThemingCapability().getName();
}
@ -229,9 +229,8 @@ public abstract class CapabilitiesUtil {
// TODO later avatar can also be checked via user fields, for now it is in Talk capability
public static boolean isAvatarEndpointAvailable(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
Capabilities capabilities;
try {
capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
return (capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getFeatures() != null &&
@ -245,9 +244,8 @@ public abstract class CapabilitiesUtil {
public static boolean canEditScopes(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
Capabilities capabilities;
try {
capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
return (capabilities != null &&
capabilities.getProvisioningCapability() != null &&
capabilities.getProvisioningCapability().getAccountPropertyScopesVersion() != null &&
@ -262,7 +260,7 @@ public abstract class CapabilitiesUtil {
public static boolean isAbleToCall(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
Capabilities capabilities = parseUserCapabilities(user);
if (capabilities != null &&
capabilities.getSpreedCapability() != null &&
capabilities.getSpreedCapability().getConfig() != null &&
@ -281,4 +279,12 @@ public abstract class CapabilitiesUtil {
}
return false;
}
private static Capabilities parseUserCapabilities(@NonNull final UserEntity user) throws IOException {
return LoganSquare.parse(user.getCapabilities(), Capabilities.class);
}
public static boolean isUnifiedSearchAvailable(@Nullable final UserEntity user) {
return hasSpreedFeatureCapability(user, "unified-search");
}
}