From bae65ebbe9022480b70ca96ef787099cccc91a5c Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 10 May 2022 16:51:47 +0200 Subject: [PATCH] rename canPostChatShareItemsDoReaction to hasChatPermission Signed-off-by: Marcel Hibbe --- .../talk/controllers/ChatController.kt | 31 ++++++++++++++----- .../talk/utils/AttendeePermissionsUtil.kt | 11 +++---- .../talk/utils/AttendeePermissionsUtilTest.kt | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 8c55ab763..cd57dd912 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -274,6 +274,8 @@ class ChatController(args: Bundle) : lateinit var mediaPlayerHandler: Handler var currentlyPlayedVoiceMessage: ChatMessage? = null + var hasChatPermission: Boolean = false + init { Log.d(TAG, "init ChatController: " + System.identityHashCode(this).toString()) @@ -307,6 +309,9 @@ class ChatController(args: Bundle) : } this.voiceOnly = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false) + + hasChatPermission = + AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission(conversationUser) } private fun getRoomInfo() { @@ -342,7 +347,8 @@ class ChatController(args: Bundle) : setTitle() try { setupMentionAutocomplete() - checkReadOnlyState() + checkShowCallButtons() + checkShowMessageInputView() checkLobbyState() if (!inConversation) { @@ -1159,13 +1165,24 @@ class ChatController(args: Bundle) : ) } - private fun checkReadOnlyState() { + private fun checkShowCallButtons() { if (isAlive()) { if (isReadOnlyConversation() || shouldShowLobby()) { disableCallButtons() - binding.messageInputView.visibility = View.GONE } else { enableCallButtons() + } + } + } + + private fun checkShowMessageInputView() { + if (isAlive()) { + if (isReadOnlyConversation() + || shouldShowLobby() + || !hasChatPermission + ) { + binding.messageInputView.visibility = View.GONE + } else { binding.messageInputView.visibility = View.VISIBLE } } @@ -2350,7 +2367,7 @@ class ChatController(args: Bundle) : super.onPrepareOptionsMenu(menu) conversationUser?.let { if (CapabilitiesUtil.hasSpreedFeatureCapability(it, "read-only-rooms")) { - checkReadOnlyState() + checkShowCallButtons() } } } @@ -2513,9 +2530,7 @@ class ChatController(args: Bundle) : } fun deleteMessage(message: IMessage?) { - if (!AttendeePermissionsUtil(currentConversation!!.permissions) - .canPostChatShareItemsDoReaction(conversationUser!!) - ) { + if (!hasChatPermission) { Log.e( TAG, "Deletion of message is skipped because of restrictions by permissions. " + "This method should not have been called!" @@ -2842,7 +2857,7 @@ class ChatController(args: Bundle) : if (!CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "delete-messages")) return false - if (AttendeePermissionsUtil(currentConversation!!.permissions).canPostChatShareItemsDoReaction(conversationUser)) return true + if (!hasChatPermission) return false return true } diff --git a/app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt b/app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt index 60fcdf304..b7b431deb 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt @@ -15,7 +15,7 @@ class AttendeePermissionsUtil(flag: Int) { var canPublishAudio: Boolean = false var canPublishVideo: Boolean = false var canPublishScreen: Boolean = false - private var canPostChatShareItemsDoReaction: Boolean = false + private var hasChatPermission: Boolean = false init { isDefault = (flag and DEFAULT) == DEFAULT @@ -26,13 +26,12 @@ class AttendeePermissionsUtil(flag: Int) { canPublishAudio = (flag and PUBLISH_AUDIO) == PUBLISH_AUDIO canPublishVideo = (flag and PUBLISH_VIDEO) == PUBLISH_VIDEO canPublishScreen = (flag and PUBLISH_SCREEN) == PUBLISH_SCREEN - canPostChatShareItemsDoReaction = - (flag and POST_CHAT_SHARE_ITEMS_DO_REACTIONS) == POST_CHAT_SHARE_ITEMS_DO_REACTIONS + hasChatPermission = (flag and CHAT) == CHAT } - fun canPostChatShareItemsDoReaction(user: UserEntity): Boolean { + fun hasChatPermission(user: UserEntity): Boolean { if (CapabilitiesUtil.hasSpreedFeatureCapability(user, "chat-permission")) { - return canPostChatShareItemsDoReaction + return hasChatPermission } // if capability is not available then the spreed version doesn't support to restrict this return true @@ -48,6 +47,6 @@ class AttendeePermissionsUtil(flag: Int) { const val PUBLISH_AUDIO = 16 const val PUBLISH_VIDEO = 32 const val PUBLISH_SCREEN = 64 - const val POST_CHAT_SHARE_ITEMS_DO_REACTIONS = 128 + const val CHAT = 128 } } \ No newline at end of file diff --git a/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt b/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt index 9ac9e23ab..bd9d29aa7 100644 --- a/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt +++ b/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt @@ -23,6 +23,6 @@ class AttendeePermissionsUtilTest : TestCase() { assertFalse(attendeePermissionsUtil.canPublishAudio) assertFalse(attendeePermissionsUtil.canPublishVideo) - // canPostChatShareItemsDoReaction() is not possible to test because userEntity is necessary + // hasChatPermission() is not possible to test because userEntity is necessary } } \ No newline at end of file