mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 17:08:34 +03:00
Rename AttendeePermissionsUtil to ParticipantPermissions
Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
c031e7063e
commit
1bbc7caeee
5 changed files with 95 additions and 68 deletions
|
@ -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
|
||||
|
|
|
@ -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!!) &&
|
||||
|
|
|
@ -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) {
|
||||
class ParticipantPermissions(
|
||||
private val user: User,
|
||||
private val conversation: Conversation
|
||||
) {
|
||||
|
||||
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
|
||||
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(user: User): Boolean {
|
||||
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
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue