diff options
author | Tim Krüger <t@timkrueger.me> | 2022-09-09 18:53:40 +0300 |
---|---|---|
committer | Tim Krüger <t@timkrueger.me> | 2022-09-26 12:07:31 +0300 |
commit | 1bbc7caeee9c3b286fc59974e7a6e98487a67fcb (patch) | |
tree | c6106d373a8763c567a1fe7bf77c70acdc1d2d54 /app/src | |
parent | c031e7063e0f9e3efd6b181d4e2b1a57bd7c7ba1 (diff) |
Rename AttendeePermissionsUtil to ParticipantPermissions
Signed-off-by: Tim Krüger <t@timkrueger.me>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt | 9 | ||||
-rw-r--r-- | app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt | 6 | ||||
-rw-r--r-- | app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt (renamed from app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt) | 48 | ||||
-rw-r--r-- | app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt | 47 | ||||
-rw-r--r-- | app/src/test/java/com/nextcloud/talk/utils/ParticipantPermissionsTest.kt | 57 |
5 files changed, 97 insertions, 70 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 8a1502543..47794ebec 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,7 @@ 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.AttendeePermissionsUtil +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 @@ -355,9 +355,7 @@ class ChatController(args: Bundle) : setTitle() hasChatPermission = - AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission( - conversationUser - ) + ParticipantPermissions(conversationUser, currentConversation!!).hasChatPermission() try { setupSwipeToReply() @@ -2727,7 +2725,8 @@ class ChatController(args: Bundle) : } private fun startACall(isVoiceOnlyCall: Boolean, callWithoutNotification: Boolean) { - if (currentConversation?.canStartCall == false && currentConversation?.hasCall == false) { + val apu = ParticipantPermissions(conversationUser!!, currentConversation!!) + if (apu.canStartCall() && currentConversation?.hasCall == false) { Toast.makeText(context, R.string.startCallForbidden, Toast.LENGTH_LONG).show() } else { ApplicationWideCurrentRoomHolder.getInstance().isDialing = 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 ed42b9ac4..1ef2262fa 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt @@ -104,7 +104,7 @@ import com.nextcloud.talk.ui.dialog.ChooseAccountShareToDialogFragment import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog import com.nextcloud.talk.users.UserManager import com.nextcloud.talk.utils.ApiUtils -import com.nextcloud.talk.utils.AttendeePermissionsUtil +import com.nextcloud.talk.utils.ParticipantPermissions import com.nextcloud.talk.utils.ClosedInterfaceImpl import com.nextcloud.talk.utils.ConductorRemapping.remapChatController import com.nextcloud.talk.utils.DisplayUtils @@ -938,9 +938,7 @@ class ConversationsListController(bundle: Bundle) : private fun handleConversation(conversation: Conversation?) { selectedConversation = conversation if (selectedConversation != null && activity != null) { - val hasChatPermission = AttendeePermissionsUtil(selectedConversation!!.permissions).hasChatPermission( - currentUser!! - ) + val hasChatPermission = ParticipantPermissions(currentUser!!, selectedConversation!!).hasChatPermission() if (showShareToScreen) { if (hasChatPermission && !isReadOnlyConversation(selectedConversation!!) && diff --git a/app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt b/app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt index 9f7c5e979..858550d47 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/AttendeePermissionsUtil.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/ParticipantPermissions.kt @@ -23,24 +23,28 @@ package com.nextcloud.talk.utils import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew /** * see https://nextcloud-talk.readthedocs.io/en/latest/constants/#attendee-permissions */ -class AttendeePermissionsUtil(flag: Int) { - - val isDefault = (flag and DEFAULT) == DEFAULT - val isCustom = (flag and CUSTOM) == CUSTOM - val canStartCall = (flag and START_CALL) == START_CALL - val canJoinCall = (flag and JOIN_CALL) == JOIN_CALL - val canIgnoreLobby = (flag and CAN_IGNORE_LOBBY) == CAN_IGNORE_LOBBY - val canPublishAudio = (flag and PUBLISH_AUDIO) == PUBLISH_AUDIO - val canPublishVideo = (flag and PUBLISH_VIDEO) == PUBLISH_VIDEO - val canPublishScreen = (flag and PUBLISH_SCREEN) == PUBLISH_SCREEN - private val hasChatPermission = (flag and CHAT) == CHAT - - fun hasChatPermission(user: User): Boolean { +class ParticipantPermissions( + private val user: User, + private val conversation: Conversation +) { + + val isDefault = (conversation.permissions and DEFAULT) == DEFAULT + 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 + 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 } @@ -48,8 +52,24 @@ class AttendeePermissionsUtil(flag: Int) { return true } + private fun hasConversationPermissions(): Boolean { + return CapabilitiesUtilNew.hasSpreedFeatureCapability( + user, + "conversation-permissions" + ) + } + + fun canStartCall(): Boolean { + return if (hasConversationPermissions()) { + canStartCall + } else { + conversation.canStartCall + } + } + companion object { - val TAG = AttendeePermissionsUtil::class.simpleName + + val TAG = ParticipantPermissions::class.simpleName const val DEFAULT = 0 const val CUSTOM = 1 const val START_CALL = 2 diff --git a/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt b/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt deleted file mode 100644 index 6ce41bd3c..000000000 --- a/app/src/test/java/com/nextcloud/talk/utils/AttendeePermissionsUtilTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Marcel Hibbe - * Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.nextcloud.talk.utils - -import junit.framework.TestCase -import org.junit.Test - -class AttendeePermissionsUtilTest : TestCase() { - - @Test - fun test_areFlagsSet() { - val attendeePermissionsUtil = - AttendeePermissionsUtil( - AttendeePermissionsUtil.PUBLISH_SCREEN or - AttendeePermissionsUtil.JOIN_CALL or - AttendeePermissionsUtil.DEFAULT - ) - - assert(attendeePermissionsUtil.canPublishScreen) - assert(attendeePermissionsUtil.canJoinCall) - assert(attendeePermissionsUtil.isDefault) - - assertFalse(attendeePermissionsUtil.isCustom) - assertFalse(attendeePermissionsUtil.canStartCall) - assertFalse(attendeePermissionsUtil.canIgnoreLobby) - assertFalse(attendeePermissionsUtil.canPublishAudio) - assertFalse(attendeePermissionsUtil.canPublishVideo) - } -} diff --git a/app/src/test/java/com/nextcloud/talk/utils/ParticipantPermissionsTest.kt b/app/src/test/java/com/nextcloud/talk/utils/ParticipantPermissionsTest.kt new file mode 100644 index 000000000..6e2a861fb --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/utils/ParticipantPermissionsTest.kt @@ -0,0 +1,57 @@ +/* + * Nextcloud Talk application + * + * @author Marcel Hibbe + * @author Tim Krüger + * Copyright (C) 2022 Tim Krüger <t@timkrueger.me> + * Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package com.nextcloud.talk.utils + +import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.models.json.conversations.Conversation +import junit.framework.TestCase +import org.junit.Test + +class ParticipantPermissionsTest : TestCase() { + + @Test + fun test_areFlagsSet() { + + val user = User() + val conversation = Conversation() + conversation.permissions = ParticipantPermissions.PUBLISH_SCREEN or + ParticipantPermissions.JOIN_CALL or + ParticipantPermissions.DEFAULT + + val attendeePermissions = + ParticipantPermissions( + user, + conversation + ) + + assert(attendeePermissions.canPublishScreen) + assert(attendeePermissions.canJoinCall) + assert(attendeePermissions.isDefault) + + assertFalse(attendeePermissions.isCustom) + assertFalse(attendeePermissions.canStartCall()) + assertFalse(attendeePermissions.canIgnoreLobby) + assertFalse(attendeePermissions.canPublishAudio) + assertFalse(attendeePermissions.canPublishVideo) + } +} |