diff options
author | Tim Krüger <t@timkrueger.me> | 2022-09-14 13:25:58 +0300 |
---|---|---|
committer | Tim Krüger <t@timkrueger.me> | 2022-09-26 12:41:10 +0300 |
commit | d0c86ec619f600f3278411fbf7f17b236f7cda36 (patch) | |
tree | 38d56768886f91ef5d1d6944648f1546af400b03 /app/src | |
parent | 7c09a86c4d2b733eca6181904d1bd44f69bfa8f7 (diff) |
Respect 'can ignore lobby' permission
Now the 'can ignore lobby' permission is respected.
The 'ChatController' has now a property of the type
'ParticipantPermissions' because it's needed multiple times. The
property will be updated in 'ChatController#getRoomInfo' if the
conversation is protected by a lobby.
The function 'Conversation#shouldShowLobby' is removed in this commit.
'Conversation' is a pure model class to hold the plain JSON response.
The logic is moved into the already existing function 'ChatController#shouldShowLobby'.
Resolves: #1783
Signed-off-by: Tim Krüger <t@timkrueger.me>
Diffstat (limited to 'app/src')
4 files changed, 46 insertions, 34 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 11dee1c92..8b95f145a 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -156,7 +156,6 @@ import com.nextcloud.talk.ui.dialog.ShowReactionsDialog import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback import com.nextcloud.talk.utils.ApiUtils -import com.nextcloud.talk.utils.ParticipantPermissions import com.nextcloud.talk.utils.ConductorRemapping import com.nextcloud.talk.utils.ConductorRemapping.remapChatController import com.nextcloud.talk.utils.ContactUtils @@ -166,6 +165,7 @@ import com.nextcloud.talk.utils.FileUtils import com.nextcloud.talk.utils.ImageEmojiEditText import com.nextcloud.talk.utils.MagicCharPolicy import com.nextcloud.talk.utils.NotificationUtils +import com.nextcloud.talk.utils.ParticipantPermissions import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME @@ -284,7 +284,7 @@ class ChatController(args: Bundle) : lateinit var mediaPlayerHandler: Handler private var currentlyPlayedVoiceMessage: ChatMessage? = null - var hasChatPermission: Boolean = false + private lateinit var participantPermissions: ParticipantPermissions private var videoURI: Uri? = null @@ -306,6 +306,7 @@ class ChatController(args: Bundle) : if (args.containsKey(KEY_ACTIVE_CONVERSATION)) { this.currentConversation = Parcels.unwrap<Conversation>(args.getParcelable(KEY_ACTIVE_CONVERSATION)) + this.participantPermissions = ParticipantPermissions(conversationUser!!, currentConversation!!) } this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "") @@ -353,9 +354,7 @@ class ChatController(args: Bundle) : ) loadAvatarForStatusBar() setTitle() - - hasChatPermission = - ParticipantPermissions(conversationUser, currentConversation!!).hasChatPermission() + participantPermissions = ParticipantPermissions(conversationUser, currentConversation!!) try { setupSwipeToReply() @@ -393,7 +392,10 @@ class ChatController(args: Bundle) : } private fun setupSwipeToReply() { - if (hasChatPermission && !isReadOnlyConversation()) { + if (this::participantPermissions.isInitialized && + participantPermissions.hasChatPermission() && + !isReadOnlyConversation() + ) { val messageSwipeController = MessageSwipeCallback( activity!!, object : MessageSwipeActions { @@ -432,6 +434,7 @@ class ChatController(args: Bundle) : if (roomId == conversation.roomId) { roomToken = conversation.token currentConversation = conversation + participantPermissions = ParticipantPermissions(conversationUser!!, currentConversation!!) setTitle() getRoomInfo() break @@ -1259,7 +1262,7 @@ class ChatController(args: Bundle) : if (isAlive()) { if (isReadOnlyConversation() || shouldShowLobby() || - !hasChatPermission + !participantPermissions.hasChatPermission() ) { binding.messageInputView.visibility = View.GONE } else { @@ -1270,7 +1273,9 @@ class ChatController(args: Bundle) : private fun shouldShowLobby(): Boolean { if (currentConversation != null) { - return currentConversation?.shouldShowLobby(conversationUser!!) == true + return currentConversation?.lobbyState == Conversation.LobbyState.LOBBY_STATE_MODERATORS_ONLY && + currentConversation?.canModerate(conversationUser!!) == false && + !participantPermissions.canIgnoreLobby() } return false } @@ -1309,14 +1314,14 @@ class ChatController(args: Bundle) : private fun checkLobbyState() { if (currentConversation != null && - currentConversation?.isLobbyViewApplicable(conversationUser!!) ?: false && + currentConversation?.isLobbyViewApplicable(conversationUser!!) == true && isAlive() ) { if (!checkingLobbyStatus) { getRoomInfo() } - if (currentConversation?.shouldShowLobby(conversationUser!!) ?: false) { + if (shouldShowLobby()) { binding.lobby.lobbyView.visibility = View.VISIBLE binding.messagesListView.visibility = View.GONE binding.messageInputView.visibility = View.GONE @@ -1608,8 +1613,8 @@ class ChatController(args: Bundle) : private fun uploadFile(fileUri: String, isVoiceMessage: Boolean) { var metaData = "" - if (!hasChatPermission) { - Log.w(TAG, "uploading file is forbidden because of missing attendee permissions") + if (!participantPermissions.hasChatPermission()) { + Log.w(TAG, "uploading file(s) is forbidden because of missing attendee permissions") return } @@ -2144,10 +2149,6 @@ class ChatController(args: Bundle) : } pullChatMessagesPending = true - if (currentConversation != null && currentConversation!!.shouldShowLobby(conversationUser!!)) { - // return - } - val fieldMap = HashMap<String, Int>() fieldMap["includeLastKnown"] = 0 @@ -2773,7 +2774,7 @@ class ChatController(args: Bundle) : currentConversation, chatMessage, conversationUser, - hasChatPermission, + participantPermissions.hasChatPermission(), ncApi ).show() } @@ -2801,7 +2802,7 @@ class ChatController(args: Bundle) : conversationUser, currentConversation, isShowMessageDeletionButton(message), - hasChatPermission, + participantPermissions.hasChatPermission(), ncApi ).show() } @@ -2813,7 +2814,7 @@ class ChatController(args: Bundle) : } fun deleteMessage(message: IMessage?) { - if (!hasChatPermission) { + if (!participantPermissions.hasChatPermission()) { Log.w( TAG, "Deletion of message is skipped because of restrictions by permissions. " + @@ -3143,7 +3144,7 @@ class ChatController(args: Bundle) : message.hasFileAttachment() -> false OBJECT_MESSAGE == message.message -> false !CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "delete-messages") -> false - !hasChatPermission -> false + !participantPermissions.hasChatPermission() -> false else -> true } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt index 1ef2262fa..14abbc2f2 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt @@ -942,7 +942,7 @@ class ConversationsListController(bundle: Bundle) : if (showShareToScreen) { if (hasChatPermission && !isReadOnlyConversation(selectedConversation!!) && - !selectedConversation!!.shouldShowLobby(currentUser!!) + !shouldShowLobby(selectedConversation!!) ) { handleSharedData() } else { @@ -961,6 +961,13 @@ class ConversationsListController(bundle: Bundle) : } } + private fun shouldShowLobby(conversation: Conversation): Boolean { + val participantPermissions = ParticipantPermissions(currentUser!!, conversation) + return conversation.lobbyState == Conversation.LobbyState.LOBBY_STATE_MODERATORS_ONLY && + !conversation.canModerate(currentUser!!) && + !participantPermissions.canIgnoreLobby() + } + private fun isReadOnlyConversation(conversation: Conversation): Boolean { return conversation.conversationReadOnlyState === Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY diff --git a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt index 54e1559c7..0160f649c 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt @@ -155,10 +155,6 @@ data class Conversation( return isParticipantOwnerOrModerator && !isLockedOneToOne(conversationUser) } - fun shouldShowLobby(conversationUser: User): Boolean { - return LobbyState.LOBBY_STATE_MODERATORS_ONLY == lobbyState && !canModerate(conversationUser) - } - fun isLobbyViewApplicable(conversationUser: User): Boolean { return !canModerate(conversationUser) && (type == ConversationType.ROOM_GROUP_CALL || type == ConversationType.ROOM_PUBLIC_CALL) diff --git a/app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt b/app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt index 858550d47..0d05771f9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt @@ -38,20 +38,12 @@ class ParticipantPermissions( val isCustom = (conversation.permissions and CUSTOM) == CUSTOM private val canStartCall = (conversation.permissions and START_CALL) == START_CALL val canJoinCall = (conversation.permissions and JOIN_CALL) == JOIN_CALL - val canIgnoreLobby = (conversation.permissions and CAN_IGNORE_LOBBY) == CAN_IGNORE_LOBBY + private val canIgnoreLobby = (conversation.permissions and CAN_IGNORE_LOBBY) == CAN_IGNORE_LOBBY val canPublishAudio = (conversation.permissions and PUBLISH_AUDIO) == PUBLISH_AUDIO val canPublishVideo = (conversation.permissions and PUBLISH_VIDEO) == PUBLISH_VIDEO val canPublishScreen = (conversation.permissions and PUBLISH_SCREEN) == PUBLISH_SCREEN private val hasChatPermission = (conversation.permissions and CHAT) == CHAT - fun hasChatPermission(): Boolean { - if (CapabilitiesUtilNew.hasSpreedFeatureCapability(user, "chat-permission")) { - return hasChatPermission - } - // if capability is not available then the spreed version doesn't support to restrict this - return true - } - private fun hasConversationPermissions(): Boolean { return CapabilitiesUtilNew.hasSpreedFeatureCapability( user, @@ -59,6 +51,14 @@ class ParticipantPermissions( ) } + fun canIgnoreLobby(): Boolean { + if (hasConversationPermissions()) { + return canIgnoreLobby + } + + return false + } + fun canStartCall(): Boolean { return if (hasConversationPermissions()) { canStartCall @@ -67,6 +67,14 @@ class ParticipantPermissions( } } + fun hasChatPermission(): Boolean { + if (CapabilitiesUtilNew.hasSpreedFeatureCapability(user, "chat-permission")) { + return hasChatPermission + } + // if capability is not available then the spreed version doesn't support to restrict this + return true + } + companion object { val TAG = ParticipantPermissions::class.simpleName |