From 625de657d4fc57a622022d61a7049a5fbe9e7884 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 7 Mar 2024 15:24:29 +0100 Subject: [PATCH] hide features if federation is not available + add capability queries (not yet used) Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/chat/ChatActivity.kt | 14 +++++++------- .../ConversationsListActivity.kt | 14 ++++++-------- .../talk/ui/dialog/MessageActionsDialog.kt | 8 +++++--- .../nextcloud/talk/utils/CapabilitiesUtil.kt | 17 ++++++++++++++++- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 0a138b2a5..a56be07a7 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -601,6 +601,7 @@ class ChatActivity : spreedCapabilities = state.spreedCapabilities chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1)) + invalidateOptionsMenu() initMessageInputView() if (conversationUser?.userId != "?" && @@ -3923,17 +3924,16 @@ class ChatActivity : val searchItem = menu.findItem(R.id.conversation_search) searchItem.isVisible = CapabilitiesUtil.isUnifiedSearchAvailable(spreedCapabilities) - if (CapabilitiesUtil.hasSpreedFeatureCapability( - spreedCapabilities, - SpreedFeatures.RICH_OBJECT_LIST_MEDIA - ) + if (currentConversation!!.remoteServer != null || + !CapabilitiesUtil.isSharedItemsAvailable(spreedCapabilities) ) { - conversationSharedItemsItem = menu.findItem(R.id.shared_items) - } else { menu.removeItem(R.id.shared_items) } - if (CapabilitiesUtil.isAbleToCall(spreedCapabilities)) { + if (currentConversation!!.remoteServer != null) { + menu.removeItem(R.id.conversation_video_call) + menu.removeItem(R.id.conversation_voice_call) + } else if (CapabilitiesUtil.isAbleToCall(spreedCapabilities)) { conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call) conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index 1c6d1142e..4df674671 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -754,15 +754,13 @@ class ConversationsListActivity : } private fun fetchPendingInvitations() { - binding.conversationListHintInclude.conversationListHintLayout.setOnClickListener { - val intent = Intent(this, InvitationsActivity::class.java) - startActivity(intent) + if (hasSpreedFeatureCapability(currentUser!!.capabilities!!.spreedCapability!!, SpreedFeatures.FEDERATION_V1)) { + binding.conversationListHintInclude.conversationListHintLayout.setOnClickListener { + val intent = Intent(this, InvitationsActivity::class.java) + startActivity(intent) + } + conversationsListViewModel.getFederationInvitations() } - - // TODO create mvvm, fetch pending invitations for all users and store in database for users, if current user - // has invitation -> show hint, if one or more other users have invitations -> show badge - - conversationsListViewModel.getFederationInvitations() } private fun initOverallLayout(isConversationListNotEmpty: Boolean) { diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/MessageActionsDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/MessageActionsDialog.kt index 1eb448614..a4a76816f 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/MessageActionsDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/MessageActionsDialog.kt @@ -165,8 +165,9 @@ class MessageActionsDialog( !(message.isDeletedCommentMessage || message.isDeleted) ) initMenuRemindMessage( - !message.isDeleted && CapabilitiesUtil.hasSpreedFeatureCapability - (spreedCapabilities, SpreedFeatures.REMIND_ME_LATER) + !message.isDeleted && + hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.REMIND_ME_LATER) && + currentConversation!!.remoteServer.isNullOrEmpty() ) initMenuMarkAsUnread( message.previousMessageId > NO_PREVIOUS_MESSAGE_ID && @@ -251,7 +252,8 @@ class MessageActionsDialog( private fun initEmojiBar(hasChatPermission: Boolean) { if (hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.REACTIONS) && isPermitted(hasChatPermission) && - isReactableMessageType(message) + isReactableMessageType(message) && + currentConversation!!.remoteServer.isNullOrEmpty() ) { checkAndSetEmojiSelfReaction(dialogMessageActionsBinding.emojiThumbsUp) dialogMessageActionsBinding.emojiThumbsUp.setOnClickListener { 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 1fa30e884..45c1dab94 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt @@ -65,7 +65,8 @@ enum class SpreedFeatures(val value: String) { UNIFIED_SEARCH("unified-search"), LOCKED_ONE_TO_ONE("locked-one-to-one-rooms"), CHAT_PERMISSION("chat-permission"), - CONVERSATION_PERMISSION("conversation-permissions") + CONVERSATION_PERMISSION("conversation-permissions"), + FEDERATION_V1("federation-v1") } @Suppress("TooManyFunctions") @@ -102,6 +103,10 @@ object CapabilitiesUtil { return false } + fun isSharedItemsAvailable(spreedCapabilities: SpreedCapability): Boolean { + return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.RICH_OBJECT_LIST_MEDIA) + } + fun getMessageMaxLength(spreedCapabilities: SpreedCapability): Int { if (spreedCapabilities.config?.containsKey("chat") == true) { val chatConfigHashMap = spreedCapabilities.config!!["chat"] @@ -155,6 +160,9 @@ object CapabilitiesUtil { } fun isUnifiedSearchAvailable(spreedCapabilities: SpreedCapability): Boolean { + if (hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.FEDERATION_V1)) { + return false + } return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH) } @@ -238,6 +246,13 @@ object CapabilitiesUtil { return false } + fun isFederationAvailable(user: User): Boolean { + return 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") + } + // endregion //region ThemingCapabilities