Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide some features if federation is not available #3698

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ class ChatActivity :
spreedCapabilities = state.spreedCapabilities
chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))

invalidateOptionsMenu()
initMessageInputView()

if (conversationUser?.userId != "?" &&
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
}

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