mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-28 09:38:14 +03:00
Message search: disable feature if unified search capability not present
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
7bfc3f60f1
commit
b097e3aac4
3 changed files with 30 additions and 18 deletions
|
@ -2502,6 +2502,8 @@ class ChatController(args: Bundle) :
|
||||||
if (CapabilitiesUtil.hasSpreedFeatureCapability(it, "read-only-rooms")) {
|
if (CapabilitiesUtil.hasSpreedFeatureCapability(it, "read-only-rooms")) {
|
||||||
checkShowCallButtons()
|
checkShowCallButtons()
|
||||||
}
|
}
|
||||||
|
val searchItem = menu.findItem(R.id.conversation_search)
|
||||||
|
searchItem.isVisible = CapabilitiesUtil.isUnifiedSearchAvailable(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,7 +326,9 @@ public class ConversationsListController extends BaseController implements Flexi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CapabilitiesUtil.isUnifiedSearchAvailable(currentUser)) {
|
||||||
searchHelper = new MessageSearchHelper(unifiedSearchRepository);
|
searchHelper = new MessageSearchHelper(unifiedSearchRepository);
|
||||||
|
}
|
||||||
|
|
||||||
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
|
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
|
||||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
||||||
|
@ -898,7 +900,9 @@ public class ConversationsListController extends BaseController implements Flexi
|
||||||
clearMessageSearchResults();
|
clearMessageSearchResults();
|
||||||
adapter.setFilter(filter);
|
adapter.setFilter(filter);
|
||||||
adapter.filterItems();
|
adapter.filterItems();
|
||||||
|
if (CapabilitiesUtil.isUnifiedSearchAvailable(currentUser)) {
|
||||||
startMessageSearch(filter);
|
startMessageSearch(filter);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resetSearchResults();
|
resetSearchResults();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class CapabilitiesUtil {
|
public abstract class CapabilitiesUtil {
|
||||||
|
@ -38,7 +39,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean hasNotificationsCapability(@Nullable UserEntity user, String capabilityName) {
|
public static boolean hasNotificationsCapability(@Nullable UserEntity user, String capabilityName) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities.getNotificationsCapability() != null &&
|
if (capabilities.getNotificationsCapability() != null &&
|
||||||
capabilities.getNotificationsCapability().getFeatures() != null) {
|
capabilities.getNotificationsCapability().getFeatures() != null) {
|
||||||
return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
|
return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
|
||||||
|
@ -53,7 +54,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean hasExternalCapability(@Nullable UserEntity user, String capabilityName) {
|
public static boolean hasExternalCapability(@Nullable UserEntity user, String capabilityName) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities.getExternalCapability() != null &&
|
if (capabilities.getExternalCapability() != null &&
|
||||||
capabilities.getExternalCapability().containsKey("v1")) {
|
capabilities.getExternalCapability().containsKey("v1")) {
|
||||||
return capabilities.getExternalCapability().get("v1").contains(capabilityName);
|
return capabilities.getExternalCapability().get("v1").contains(capabilityName);
|
||||||
|
@ -82,7 +83,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean hasSpreedFeatureCapability(@Nullable UserEntity user, String capabilityName) {
|
public static boolean hasSpreedFeatureCapability(@Nullable UserEntity user, String capabilityName) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null && capabilities.getSpreedCapability() != null &&
|
if (capabilities != null && capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getFeatures() != null) {
|
capabilities.getSpreedCapability().getFeatures() != null) {
|
||||||
return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
|
return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
|
||||||
|
@ -97,7 +98,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static Integer getMessageMaxLength(@Nullable UserEntity user) {
|
public static Integer getMessageMaxLength(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null &&
|
if (capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getConfig() != null &&
|
capabilities.getSpreedCapability().getConfig() != null &&
|
||||||
|
@ -125,7 +126,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean isPhoneBookIntegrationAvailable(@Nullable UserEntity user) {
|
public static boolean isPhoneBookIntegrationAvailable(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
return capabilities != null &&
|
return capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getFeatures() != null &&
|
capabilities.getSpreedCapability().getFeatures() != null &&
|
||||||
|
@ -140,7 +141,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean isReadStatusAvailable(@Nullable UserEntity user) {
|
public static boolean isReadStatusAvailable(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null &&
|
if (capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getConfig() != null &&
|
capabilities.getSpreedCapability().getConfig() != null &&
|
||||||
|
@ -158,7 +159,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean isReadStatusPrivate(@Nullable UserEntity user) {
|
public static boolean isReadStatusPrivate(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null &&
|
if (capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getConfig() != null &&
|
capabilities.getSpreedCapability().getConfig() != null &&
|
||||||
|
@ -178,7 +179,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean isUserStatusAvailable(@Nullable UserEntity user) {
|
public static boolean isUserStatusAvailable(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities.getUserStatusCapability() != null &&
|
if (capabilities.getUserStatusCapability() != null &&
|
||||||
capabilities.getUserStatusCapability().getEnabled() &&
|
capabilities.getUserStatusCapability().getEnabled() &&
|
||||||
capabilities.getUserStatusCapability().getSupportsEmoji()) {
|
capabilities.getUserStatusCapability().getSupportsEmoji()) {
|
||||||
|
@ -194,7 +195,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static String getAttachmentFolder(@Nullable UserEntity user) {
|
public static String getAttachmentFolder(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null &&
|
if (capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getConfig() != null &&
|
capabilities.getSpreedCapability().getConfig() != null &&
|
||||||
|
@ -213,9 +214,8 @@ public abstract class CapabilitiesUtil {
|
||||||
|
|
||||||
public static String getServerName(@Nullable UserEntity user) {
|
public static String getServerName(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
Capabilities capabilities;
|
|
||||||
try {
|
try {
|
||||||
capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null && capabilities.getThemingCapability() != null) {
|
if (capabilities != null && capabilities.getThemingCapability() != null) {
|
||||||
return capabilities.getThemingCapability().getName();
|
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
|
// TODO later avatar can also be checked via user fields, for now it is in Talk capability
|
||||||
public static boolean isAvatarEndpointAvailable(@Nullable UserEntity user) {
|
public static boolean isAvatarEndpointAvailable(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
Capabilities capabilities;
|
|
||||||
try {
|
try {
|
||||||
capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
return (capabilities != null &&
|
return (capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getFeatures() != null &&
|
capabilities.getSpreedCapability().getFeatures() != null &&
|
||||||
|
@ -245,9 +244,8 @@ public abstract class CapabilitiesUtil {
|
||||||
|
|
||||||
public static boolean canEditScopes(@Nullable UserEntity user) {
|
public static boolean canEditScopes(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
Capabilities capabilities;
|
|
||||||
try {
|
try {
|
||||||
capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
return (capabilities != null &&
|
return (capabilities != null &&
|
||||||
capabilities.getProvisioningCapability() != null &&
|
capabilities.getProvisioningCapability() != null &&
|
||||||
capabilities.getProvisioningCapability().getAccountPropertyScopesVersion() != null &&
|
capabilities.getProvisioningCapability().getAccountPropertyScopesVersion() != null &&
|
||||||
|
@ -262,7 +260,7 @@ public abstract class CapabilitiesUtil {
|
||||||
public static boolean isAbleToCall(@Nullable UserEntity user) {
|
public static boolean isAbleToCall(@Nullable UserEntity user) {
|
||||||
if (user != null && user.getCapabilities() != null) {
|
if (user != null && user.getCapabilities() != null) {
|
||||||
try {
|
try {
|
||||||
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
|
Capabilities capabilities = parseUserCapabilities(user);
|
||||||
if (capabilities != null &&
|
if (capabilities != null &&
|
||||||
capabilities.getSpreedCapability() != null &&
|
capabilities.getSpreedCapability() != null &&
|
||||||
capabilities.getSpreedCapability().getConfig() != null &&
|
capabilities.getSpreedCapability().getConfig() != null &&
|
||||||
|
@ -281,4 +279,12 @@ public abstract class CapabilitiesUtil {
|
||||||
}
|
}
|
||||||
return false;
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue