hide features if federation is not available

+ add capability queries (not yet used)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-03-07 15:24:29 +01:00
parent 11a7764bad
commit 625de657d4
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
4 changed files with 34 additions and 19 deletions

View file

@ -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)

View file

@ -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) {

View file

@ -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 {

View file

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