Merge pull request #3698 from nextcloud/feature/noid/handleFederationFeaturesByCapabilities

hide some features if federation is not available
This commit is contained in:
Marcel Hibbe 2024-03-12 11:35:30 +01:00 committed by GitHub
commit 3832e84e80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 19 deletions

View file

@ -601,6 +601,7 @@ class ChatActivity :
spreedCapabilities = state.spreedCapabilities spreedCapabilities = state.spreedCapabilities
chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1)) chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
invalidateOptionsMenu()
initMessageInputView() initMessageInputView()
if (conversationUser?.userId != "?" && if (conversationUser?.userId != "?" &&
@ -3923,17 +3924,16 @@ class ChatActivity :
val searchItem = menu.findItem(R.id.conversation_search) val searchItem = menu.findItem(R.id.conversation_search)
searchItem.isVisible = CapabilitiesUtil.isUnifiedSearchAvailable(spreedCapabilities) searchItem.isVisible = CapabilitiesUtil.isUnifiedSearchAvailable(spreedCapabilities)
if (CapabilitiesUtil.hasSpreedFeatureCapability( if (currentConversation!!.remoteServer != null ||
spreedCapabilities, !CapabilitiesUtil.isSharedItemsAvailable(spreedCapabilities)
SpreedFeatures.RICH_OBJECT_LIST_MEDIA
)
) { ) {
conversationSharedItemsItem = menu.findItem(R.id.shared_items)
} else {
menu.removeItem(R.id.shared_items) 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) conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call)
conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call) conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call)

View file

@ -754,16 +754,14 @@ class ConversationsListActivity :
} }
private fun fetchPendingInvitations() { private fun fetchPendingInvitations() {
if (hasSpreedFeatureCapability(currentUser!!.capabilities!!.spreedCapability!!, SpreedFeatures.FEDERATION_V1)) {
binding.conversationListHintInclude.conversationListHintLayout.setOnClickListener { binding.conversationListHintInclude.conversationListHintLayout.setOnClickListener {
val intent = Intent(this, InvitationsActivity::class.java) val intent = Intent(this, InvitationsActivity::class.java)
startActivity(intent) startActivity(intent)
} }
// 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() conversationsListViewModel.getFederationInvitations()
} }
}
private fun initOverallLayout(isConversationListNotEmpty: Boolean) { private fun initOverallLayout(isConversationListNotEmpty: Boolean) {
if (isConversationListNotEmpty) { if (isConversationListNotEmpty) {

View file

@ -165,8 +165,9 @@ class MessageActionsDialog(
!(message.isDeletedCommentMessage || message.isDeleted) !(message.isDeletedCommentMessage || message.isDeleted)
) )
initMenuRemindMessage( initMenuRemindMessage(
!message.isDeleted && CapabilitiesUtil.hasSpreedFeatureCapability !message.isDeleted &&
(spreedCapabilities, SpreedFeatures.REMIND_ME_LATER) hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.REMIND_ME_LATER) &&
currentConversation!!.remoteServer.isNullOrEmpty()
) )
initMenuMarkAsUnread( initMenuMarkAsUnread(
message.previousMessageId > NO_PREVIOUS_MESSAGE_ID && message.previousMessageId > NO_PREVIOUS_MESSAGE_ID &&
@ -251,7 +252,8 @@ class MessageActionsDialog(
private fun initEmojiBar(hasChatPermission: Boolean) { private fun initEmojiBar(hasChatPermission: Boolean) {
if (hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.REACTIONS) && if (hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.REACTIONS) &&
isPermitted(hasChatPermission) && isPermitted(hasChatPermission) &&
isReactableMessageType(message) isReactableMessageType(message) &&
currentConversation!!.remoteServer.isNullOrEmpty()
) { ) {
checkAndSetEmojiSelfReaction(dialogMessageActionsBinding.emojiThumbsUp) checkAndSetEmojiSelfReaction(dialogMessageActionsBinding.emojiThumbsUp)
dialogMessageActionsBinding.emojiThumbsUp.setOnClickListener { dialogMessageActionsBinding.emojiThumbsUp.setOnClickListener {

View file

@ -65,7 +65,8 @@ enum class SpreedFeatures(val value: String) {
UNIFIED_SEARCH("unified-search"), UNIFIED_SEARCH("unified-search"),
LOCKED_ONE_TO_ONE("locked-one-to-one-rooms"), LOCKED_ONE_TO_ONE("locked-one-to-one-rooms"),
CHAT_PERMISSION("chat-permission"), CHAT_PERMISSION("chat-permission"),
CONVERSATION_PERMISSION("conversation-permissions") CONVERSATION_PERMISSION("conversation-permissions"),
FEDERATION_V1("federation-v1")
} }
@Suppress("TooManyFunctions") @Suppress("TooManyFunctions")
@ -102,6 +103,10 @@ object CapabilitiesUtil {
return false return false
} }
fun isSharedItemsAvailable(spreedCapabilities: SpreedCapability): Boolean {
return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.RICH_OBJECT_LIST_MEDIA)
}
fun getMessageMaxLength(spreedCapabilities: SpreedCapability): Int { fun getMessageMaxLength(spreedCapabilities: SpreedCapability): Int {
if (spreedCapabilities.config?.containsKey("chat") == true) { if (spreedCapabilities.config?.containsKey("chat") == true) {
val chatConfigHashMap = spreedCapabilities.config!!["chat"] val chatConfigHashMap = spreedCapabilities.config!!["chat"]
@ -155,6 +160,9 @@ object CapabilitiesUtil {
} }
fun isUnifiedSearchAvailable(spreedCapabilities: SpreedCapability): Boolean { fun isUnifiedSearchAvailable(spreedCapabilities: SpreedCapability): Boolean {
if (hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.FEDERATION_V1)) {
return false
}
return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH) return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH)
} }
@ -238,6 +246,13 @@ object CapabilitiesUtil {
return false 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 // endregion
//region ThemingCapabilities //region ThemingCapabilities