mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 20:19:42 +01:00
Rename AttendeePermissionsUtil to ParticipantPermissions
Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
c031e7063e
commit
1bbc7caeee
@ -156,7 +156,7 @@ import com.nextcloud.talk.ui.dialog.ShowReactionsDialog
|
|||||||
import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions
|
import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions
|
||||||
import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
|
import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
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
|
||||||
import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
|
import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
|
||||||
import com.nextcloud.talk.utils.ContactUtils
|
import com.nextcloud.talk.utils.ContactUtils
|
||||||
@ -355,9 +355,7 @@ class ChatController(args: Bundle) :
|
|||||||
setTitle()
|
setTitle()
|
||||||
|
|
||||||
hasChatPermission =
|
hasChatPermission =
|
||||||
AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission(
|
ParticipantPermissions(conversationUser, currentConversation!!).hasChatPermission()
|
||||||
conversationUser
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setupSwipeToReply()
|
setupSwipeToReply()
|
||||||
@ -2727,7 +2725,8 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startACall(isVoiceOnlyCall: Boolean, callWithoutNotification: Boolean) {
|
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()
|
Toast.makeText(context, R.string.startCallForbidden, Toast.LENGTH_LONG).show()
|
||||||
} else {
|
} else {
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().isDialing = true
|
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.ui.dialog.ConversationsListBottomDialog
|
||||||
import com.nextcloud.talk.users.UserManager
|
import com.nextcloud.talk.users.UserManager
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
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.ClosedInterfaceImpl
|
||||||
import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
|
import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
|
||||||
import com.nextcloud.talk.utils.DisplayUtils
|
import com.nextcloud.talk.utils.DisplayUtils
|
||||||
@ -938,9 +938,7 @@ class ConversationsListController(bundle: Bundle) :
|
|||||||
private fun handleConversation(conversation: Conversation?) {
|
private fun handleConversation(conversation: Conversation?) {
|
||||||
selectedConversation = conversation
|
selectedConversation = conversation
|
||||||
if (selectedConversation != null && activity != null) {
|
if (selectedConversation != null && activity != null) {
|
||||||
val hasChatPermission = AttendeePermissionsUtil(selectedConversation!!.permissions).hasChatPermission(
|
val hasChatPermission = ParticipantPermissions(currentUser!!, selectedConversation!!).hasChatPermission()
|
||||||
currentUser!!
|
|
||||||
)
|
|
||||||
if (showShareToScreen) {
|
if (showShareToScreen) {
|
||||||
if (hasChatPermission &&
|
if (hasChatPermission &&
|
||||||
!isReadOnlyConversation(selectedConversation!!) &&
|
!isReadOnlyConversation(selectedConversation!!) &&
|
||||||
|
@ -23,24 +23,28 @@
|
|||||||
package com.nextcloud.talk.utils
|
package com.nextcloud.talk.utils
|
||||||
|
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew
|
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* see https://nextcloud-talk.readthedocs.io/en/latest/constants/#attendee-permissions
|
* 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 isDefault = (conversation.permissions and DEFAULT) == DEFAULT
|
||||||
val isCustom = (flag and CUSTOM) == CUSTOM
|
val isCustom = (conversation.permissions and CUSTOM) == CUSTOM
|
||||||
val canStartCall = (flag and START_CALL) == START_CALL
|
private val canStartCall = (conversation.permissions and START_CALL) == START_CALL
|
||||||
val canJoinCall = (flag and JOIN_CALL) == JOIN_CALL
|
val canJoinCall = (conversation.permissions and JOIN_CALL) == JOIN_CALL
|
||||||
val canIgnoreLobby = (flag and CAN_IGNORE_LOBBY) == CAN_IGNORE_LOBBY
|
val canIgnoreLobby = (conversation.permissions and CAN_IGNORE_LOBBY) == CAN_IGNORE_LOBBY
|
||||||
val canPublishAudio = (flag and PUBLISH_AUDIO) == PUBLISH_AUDIO
|
val canPublishAudio = (conversation.permissions and PUBLISH_AUDIO) == PUBLISH_AUDIO
|
||||||
val canPublishVideo = (flag and PUBLISH_VIDEO) == PUBLISH_VIDEO
|
val canPublishVideo = (conversation.permissions and PUBLISH_VIDEO) == PUBLISH_VIDEO
|
||||||
val canPublishScreen = (flag and PUBLISH_SCREEN) == PUBLISH_SCREEN
|
val canPublishScreen = (conversation.permissions and PUBLISH_SCREEN) == PUBLISH_SCREEN
|
||||||
private val hasChatPermission = (flag and CHAT) == CHAT
|
private val hasChatPermission = (conversation.permissions and CHAT) == CHAT
|
||||||
|
|
||||||
fun hasChatPermission(user: User): Boolean {
|
fun hasChatPermission(): Boolean {
|
||||||
if (CapabilitiesUtilNew.hasSpreedFeatureCapability(user, "chat-permission")) {
|
if (CapabilitiesUtilNew.hasSpreedFeatureCapability(user, "chat-permission")) {
|
||||||
return hasChatPermission
|
return hasChatPermission
|
||||||
}
|
}
|
||||||
@ -48,8 +52,24 @@ class AttendeePermissionsUtil(flag: Int) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hasConversationPermissions(): Boolean {
|
||||||
|
return CapabilitiesUtilNew.hasSpreedFeatureCapability(
|
||||||
|
user,
|
||||||
|
"conversation-permissions"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun canStartCall(): Boolean {
|
||||||
|
return if (hasConversationPermissions()) {
|
||||||
|
canStartCall
|
||||||
|
} else {
|
||||||
|
conversation.canStartCall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = AttendeePermissionsUtil::class.simpleName
|
|
||||||
|
val TAG = ParticipantPermissions::class.simpleName
|
||||||
const val DEFAULT = 0
|
const val DEFAULT = 0
|
||||||
const val CUSTOM = 1
|
const val CUSTOM = 1
|
||||||
const val START_CALL = 2
|
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 New Issue
Block a user