From 1d859637a86e416c0327199a0d48da002239e582 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 8 Nov 2024 14:44:55 +0100 Subject: [PATCH] delete isArchiveConversationsAvailable only more complex checks should be made in CapabilitiesUtil, just checking a capability should be done directly via hasSpreedFeatureCapability Signed-off-by: Marcel Hibbe --- .../ConversationInfoActivity.kt | 3 +- .../nextcloud/talk/utils/CapabilitiesUtil.kt | 58 +++++++------------ 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index 9f1809eee9..aed4473ef3 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -77,6 +77,7 @@ import com.nextcloud.talk.shareditems.activities.SharedItemsActivity import com.nextcloud.talk.ui.dialog.DialogBanListFragment import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.CapabilitiesUtil +import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability import com.nextcloud.talk.utils.ConversationUtils import com.nextcloud.talk.utils.DateConstants import com.nextcloud.talk.utils.DateUtils @@ -791,7 +792,7 @@ class ConversationInfoActivity : } } - if (!CapabilitiesUtil.isArchiveConversationsAvailable(spreedCapabilities)) { + if (!hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ARCHIVE_CONVERSATIONS)) { binding.archiveConversationBtn.visibility = GONE binding.archiveConversationTextHint.visibility = GONE } diff --git a/app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt b/app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt index 996262296d..54bb10e2fc 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt @@ -84,14 +84,11 @@ object CapabilitiesUtil { //region CoreCapabilities @JvmStatic - fun isLinkPreviewAvailable(user: User): Boolean { - return user.capabilities?.coreCapability?.referenceApi != null && + fun isLinkPreviewAvailable(user: User): Boolean = + user.capabilities?.coreCapability?.referenceApi != null && user.capabilities?.coreCapability?.referenceApi == "true" - } - fun canGeneratePrettyURL(user: User): Boolean { - return user.capabilities?.coreCapability?.modRewriteWorking == true - } + fun canGeneratePrettyURL(user: User): Boolean = user.capabilities?.coreCapability?.modRewriteWorking == true // endregion @@ -105,9 +102,8 @@ object CapabilitiesUtil { return false } - fun isSharedItemsAvailable(spreedCapabilities: SpreedCapability): Boolean { - return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.RICH_OBJECT_LIST_MEDIA) - } + fun isSharedItemsAvailable(spreedCapabilities: SpreedCapability): Boolean = + hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.RICH_OBJECT_LIST_MEDIA) fun getMessageMaxLength(spreedCapabilities: SpreedCapability): Int { if (spreedCapabilities.config?.containsKey("chat") == true) { @@ -157,16 +153,14 @@ object CapabilitiesUtil { return "/Talk" } - fun isConversationDescriptionEndpointAvailable(spreedCapabilities: SpreedCapability): Boolean { - return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ROOM_DESCRIPTION) - } + fun isConversationDescriptionEndpointAvailable(spreedCapabilities: SpreedCapability): Boolean = + hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ROOM_DESCRIPTION) - fun isUnifiedSearchAvailable(spreedCapabilities: SpreedCapability): Boolean { - return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH) - } + fun isUnifiedSearchAvailable(spreedCapabilities: SpreedCapability): Boolean = + hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH) - fun isAbleToCall(spreedCapabilities: SpreedCapability): Boolean { - return if ( + fun isAbleToCall(spreedCapabilities: SpreedCapability): Boolean = + if ( spreedCapabilities.config?.containsKey("call") == true && spreedCapabilities.config!!["call"] != null && spreedCapabilities.config!!["call"]!!.containsKey("enabled") @@ -176,7 +170,6 @@ object CapabilitiesUtil { // older nextcloud versions without the capability can't disable the calls true } - } fun isCallReactionsSupported(user: User?): Boolean { if (user?.capabilities != null) { @@ -188,12 +181,11 @@ object CapabilitiesUtil { return false } - fun isTranslationsSupported(spreedCapabilities: SpreedCapability): Boolean { - return spreedCapabilities.config?.containsKey("chat") == true && + fun isTranslationsSupported(spreedCapabilities: SpreedCapability): Boolean = + spreedCapabilities.config?.containsKey("chat") == true && spreedCapabilities.config!!["chat"] != null && spreedCapabilities.config!!["chat"]!!.containsKey("has-translation-providers") && spreedCapabilities.config!!["chat"]!!["has-translation-providers"] == true - } fun getRecordingConsentType(spreedCapabilities: SpreedCapability): Int { if ( @@ -213,9 +205,8 @@ object CapabilitiesUtil { return RECORDING_CONSENT_NOT_REQUIRED } - fun isBanningAvailable(spreedCapabilities: SpreedCapability): Boolean { - return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.BAN_V1) - } + fun isBanningAvailable(spreedCapabilities: SpreedCapability): Boolean = + hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.BAN_V1) // endregion @@ -249,16 +240,11 @@ object CapabilitiesUtil { return false } - fun isFederationAvailable(user: User): Boolean { - return hasSpreedFeatureCapability(user.capabilities!!.spreedCapability!!, SpreedFeatures.FEDERATION_V1) && + fun isFederationAvailable(user: User): Boolean = + hasSpreedFeatureCapability(user.capabilities!!.spreedCapability!!, SpreedFeatures.FEDERATION_V1) && user.capabilities!!.spreedCapability!!.config?.containsKey("federation") == true && user.capabilities!!.spreedCapability!!.config!!["federation"] != null && user.capabilities!!.spreedCapability!!.config!!["federation"]!!.containsKey("enabled") - } - - fun isArchiveConversationsAvailable(spreedCapabilities: SpreedCapability): Boolean { - return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ARCHIVE_CONVERSATIONS) - } // endregion @@ -275,20 +261,18 @@ object CapabilitiesUtil { //region ProvisioningCapabilities - fun canEditScopes(user: User): Boolean { - return user.capabilities?.provisioningCapability?.accountPropertyScopesVersion != null && + fun canEditScopes(user: User): Boolean = + user.capabilities?.provisioningCapability?.accountPropertyScopesVersion != null && user.capabilities!!.provisioningCapability!!.accountPropertyScopesVersion!! > 1 - } // endregion //region UserStatusCapabilities @JvmStatic - fun isUserStatusAvailable(user: User): Boolean { - return user.capabilities?.userStatusCapability?.enabled == true && + fun isUserStatusAvailable(user: User): Boolean = + user.capabilities?.userStatusCapability?.enabled == true && user.capabilities?.userStatusCapability?.supportsEmoji == true - } // endregion