|
@@ -0,0 +1,230 @@
|
|
|
+/*
|
|
|
+ * Nextcloud Talk application
|
|
|
+ *
|
|
|
+ * @author Andy Scherzinger
|
|
|
+ * @author Mario Danic
|
|
|
+ * Copyright (C) 2021 Andy Scherzinger (info@andy-scherzinger.de)
|
|
|
+ * 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.utils.database.user;
|
|
|
+
|
|
|
+import com.nextcloud.talk.data.user.model.UserNgEntity;
|
|
|
+import com.nextcloud.talk.models.json.capabilities.Capabilities;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+public abstract class CapabilitiesNgUtil {
|
|
|
+ private static final String TAG = CapabilitiesNgUtil.class.getSimpleName();
|
|
|
+
|
|
|
+ public static boolean hasNotificationsCapability(@Nullable UserNgEntity user, String capabilityName) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities.getNotificationsCapability() != null &&
|
|
|
+ capabilities.getNotificationsCapability().getFeatures() != null) {
|
|
|
+ return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean hasExternalCapability(@Nullable UserNgEntity user, String capabilityName) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities.getExternalCapability() != null &&
|
|
|
+ capabilities.getExternalCapability().containsKey("v1")) {
|
|
|
+ return capabilities.getExternalCapability().get("v1").contains(capabilityName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isServerEOL(@Nullable UserNgEntity user) {
|
|
|
+ // Capability is available since Talk 4 => Nextcloud 14 => Autmn 2018
|
|
|
+ return !hasSpreedFeatureCapability(user, "no-ping");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isServerAlmostEOL(@Nullable UserNgEntity user) {
|
|
|
+ // Capability is available since Talk 8 => Nextcloud 18 => January 2020
|
|
|
+ return !hasSpreedFeatureCapability(user, "chat-replies");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean canSetChatReadMarker(@Nullable UserNgEntity user) {
|
|
|
+ return hasSpreedFeatureCapability(user, "chat-read-marker");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean hasSpreedFeatureCapability(@Nullable UserNgEntity user, String capabilityName) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities != null && capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getFeatures() != null) {
|
|
|
+ return capabilities.getSpreedCapability().getFeatures().contains(capabilityName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Integer getMessageMaxLength(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isPhoneBookIntegrationAvailable(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ return capabilities != null &&
|
|
|
+ capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getFeatures() != null &&
|
|
|
+ capabilities.getSpreedCapability().getFeatures().contains("phonebook-search");
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isReadStatusAvailable(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities != null &&
|
|
|
+ capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig().containsKey("chat")) {
|
|
|
+ Map<String, String> map = capabilities.getSpreedCapability().getConfig().get("chat");
|
|
|
+ return map != null && map.containsKey("read-privacy");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isReadStatusPrivate(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities != null &&
|
|
|
+ capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig().containsKey("chat")) {
|
|
|
+ HashMap<String, String> map = capabilities.getSpreedCapability().getConfig().get("chat");
|
|
|
+ if (map != null && map.containsKey("read-privacy")) {
|
|
|
+ return Integer.parseInt(map.get("read-privacy")) == 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isUserStatusAvailable(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities.getUserStatusCapability() != null &&
|
|
|
+ capabilities.getUserStatusCapability().getEnabled() &&
|
|
|
+ capabilities.getUserStatusCapability().getSupportsEmoji()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getAttachmentFolder(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities != null &&
|
|
|
+ capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig().containsKey("attachments")) {
|
|
|
+ HashMap<String, String> map = capabilities.getSpreedCapability().getConfig().get("attachments");
|
|
|
+ if (map != null && map.containsKey("folder")) {
|
|
|
+ return map.get("folder");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "/Talk";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getServerName(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities != null && capabilities.getThemingCapability() != null) {
|
|
|
+ return capabilities.getThemingCapability().getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO later avatar can also be checked via user fields, for now it is in Talk capability
|
|
|
+ public static boolean isAvatarEndpointAvailable(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ return (capabilities != null &&
|
|
|
+ capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getFeatures() != null &&
|
|
|
+ capabilities.getSpreedCapability().getFeatures().contains("temp-user-avatar-api"));
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean canEditScopes(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ return (capabilities != null &&
|
|
|
+ capabilities.getProvisioningCapability() != null &&
|
|
|
+ capabilities.getProvisioningCapability().getAccountPropertyScopesVersion() != null &&
|
|
|
+ capabilities.getProvisioningCapability().getAccountPropertyScopesVersion() > 1);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isAbleToCall(@Nullable UserNgEntity user) {
|
|
|
+ if (user != null && user.getCapabilities() != null) {
|
|
|
+ Capabilities capabilities = user.getCapabilities();
|
|
|
+ if (capabilities != null &&
|
|
|
+ capabilities.getSpreedCapability() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig() != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig().containsKey("call") &&
|
|
|
+ capabilities.getSpreedCapability().getConfig().get("call") != null &&
|
|
|
+ capabilities.getSpreedCapability().getConfig().get("call").containsKey("enabled")) {
|
|
|
+ return Boolean.parseBoolean(
|
|
|
+ capabilities.getSpreedCapability().getConfig().get("call").get("enabled"));
|
|
|
+ } else {
|
|
|
+ // older nextcloud versions without the capability can't disable the calls
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isUnifiedSearchAvailable(@Nullable final UserNgEntity user) {
|
|
|
+ return hasSpreedFeatureCapability(user, "unified-search");
|
|
|
+ }
|
|
|
+}
|