Skip to content

Commit

Permalink
delete isArchiveConversationsAvailable
Browse files Browse the repository at this point in the history
only more complex checks should be made in CapabilitiesUtil, just checking a capability should be done directly via hasSpreedFeatureCapability

Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Nov 8, 2024
1 parent 8cd8a30 commit 1d85963
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -791,7 +792,7 @@ class ConversationInfoActivity :
}
}

if (!CapabilitiesUtil.isArchiveConversationsAvailable(spreedCapabilities)) {
if (!hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ARCHIVE_CONVERSATIONS)) {
binding.archiveConversationBtn.visibility = GONE
binding.archiveConversationTextHint.visibility = GONE
}
Expand Down
58 changes: 21 additions & 37 deletions app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand All @@ -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 (
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 1d85963

Please sign in to comment.