mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
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>
This commit is contained in:
parent
7c09a86c4d
commit
d0c86ec619
@ -156,7 +156,6 @@ 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.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
|
||||||
@ -166,6 +165,7 @@ import com.nextcloud.talk.utils.FileUtils
|
|||||||
import com.nextcloud.talk.utils.ImageEmojiEditText
|
import com.nextcloud.talk.utils.ImageEmojiEditText
|
||||||
import com.nextcloud.talk.utils.MagicCharPolicy
|
import com.nextcloud.talk.utils.MagicCharPolicy
|
||||||
import com.nextcloud.talk.utils.NotificationUtils
|
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
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
|
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME
|
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME
|
||||||
@ -284,7 +284,7 @@ class ChatController(args: Bundle) :
|
|||||||
lateinit var mediaPlayerHandler: Handler
|
lateinit var mediaPlayerHandler: Handler
|
||||||
private var currentlyPlayedVoiceMessage: ChatMessage? = null
|
private var currentlyPlayedVoiceMessage: ChatMessage? = null
|
||||||
|
|
||||||
var hasChatPermission: Boolean = false
|
private lateinit var participantPermissions: ParticipantPermissions
|
||||||
|
|
||||||
private var videoURI: Uri? = null
|
private var videoURI: Uri? = null
|
||||||
|
|
||||||
@ -306,6 +306,7 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
if (args.containsKey(KEY_ACTIVE_CONVERSATION)) {
|
if (args.containsKey(KEY_ACTIVE_CONVERSATION)) {
|
||||||
this.currentConversation = Parcels.unwrap<Conversation>(args.getParcelable(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, "")
|
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "")
|
||||||
@ -353,9 +354,7 @@ class ChatController(args: Bundle) :
|
|||||||
)
|
)
|
||||||
loadAvatarForStatusBar()
|
loadAvatarForStatusBar()
|
||||||
setTitle()
|
setTitle()
|
||||||
|
participantPermissions = ParticipantPermissions(conversationUser, currentConversation!!)
|
||||||
hasChatPermission =
|
|
||||||
ParticipantPermissions(conversationUser, currentConversation!!).hasChatPermission()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setupSwipeToReply()
|
setupSwipeToReply()
|
||||||
@ -393,7 +392,10 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSwipeToReply() {
|
private fun setupSwipeToReply() {
|
||||||
if (hasChatPermission && !isReadOnlyConversation()) {
|
if (this::participantPermissions.isInitialized &&
|
||||||
|
participantPermissions.hasChatPermission() &&
|
||||||
|
!isReadOnlyConversation()
|
||||||
|
) {
|
||||||
val messageSwipeController = MessageSwipeCallback(
|
val messageSwipeController = MessageSwipeCallback(
|
||||||
activity!!,
|
activity!!,
|
||||||
object : MessageSwipeActions {
|
object : MessageSwipeActions {
|
||||||
@ -432,6 +434,7 @@ class ChatController(args: Bundle) :
|
|||||||
if (roomId == conversation.roomId) {
|
if (roomId == conversation.roomId) {
|
||||||
roomToken = conversation.token
|
roomToken = conversation.token
|
||||||
currentConversation = conversation
|
currentConversation = conversation
|
||||||
|
participantPermissions = ParticipantPermissions(conversationUser!!, currentConversation!!)
|
||||||
setTitle()
|
setTitle()
|
||||||
getRoomInfo()
|
getRoomInfo()
|
||||||
break
|
break
|
||||||
@ -1259,7 +1262,7 @@ class ChatController(args: Bundle) :
|
|||||||
if (isAlive()) {
|
if (isAlive()) {
|
||||||
if (isReadOnlyConversation() ||
|
if (isReadOnlyConversation() ||
|
||||||
shouldShowLobby() ||
|
shouldShowLobby() ||
|
||||||
!hasChatPermission
|
!participantPermissions.hasChatPermission()
|
||||||
) {
|
) {
|
||||||
binding.messageInputView.visibility = View.GONE
|
binding.messageInputView.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
@ -1270,7 +1273,9 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
private fun shouldShowLobby(): Boolean {
|
private fun shouldShowLobby(): Boolean {
|
||||||
if (currentConversation != null) {
|
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
|
return false
|
||||||
}
|
}
|
||||||
@ -1309,14 +1314,14 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
private fun checkLobbyState() {
|
private fun checkLobbyState() {
|
||||||
if (currentConversation != null &&
|
if (currentConversation != null &&
|
||||||
currentConversation?.isLobbyViewApplicable(conversationUser!!) ?: false &&
|
currentConversation?.isLobbyViewApplicable(conversationUser!!) == true &&
|
||||||
isAlive()
|
isAlive()
|
||||||
) {
|
) {
|
||||||
if (!checkingLobbyStatus) {
|
if (!checkingLobbyStatus) {
|
||||||
getRoomInfo()
|
getRoomInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentConversation?.shouldShowLobby(conversationUser!!) ?: false) {
|
if (shouldShowLobby()) {
|
||||||
binding.lobby.lobbyView.visibility = View.VISIBLE
|
binding.lobby.lobbyView.visibility = View.VISIBLE
|
||||||
binding.messagesListView.visibility = View.GONE
|
binding.messagesListView.visibility = View.GONE
|
||||||
binding.messageInputView.visibility = View.GONE
|
binding.messageInputView.visibility = View.GONE
|
||||||
@ -1608,8 +1613,8 @@ class ChatController(args: Bundle) :
|
|||||||
private fun uploadFile(fileUri: String, isVoiceMessage: Boolean) {
|
private fun uploadFile(fileUri: String, isVoiceMessage: Boolean) {
|
||||||
var metaData = ""
|
var metaData = ""
|
||||||
|
|
||||||
if (!hasChatPermission) {
|
if (!participantPermissions.hasChatPermission()) {
|
||||||
Log.w(TAG, "uploading file is forbidden because of missing attendee permissions")
|
Log.w(TAG, "uploading file(s) is forbidden because of missing attendee permissions")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2144,10 +2149,6 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
pullChatMessagesPending = true
|
pullChatMessagesPending = true
|
||||||
|
|
||||||
if (currentConversation != null && currentConversation!!.shouldShowLobby(conversationUser!!)) {
|
|
||||||
// return
|
|
||||||
}
|
|
||||||
|
|
||||||
val fieldMap = HashMap<String, Int>()
|
val fieldMap = HashMap<String, Int>()
|
||||||
fieldMap["includeLastKnown"] = 0
|
fieldMap["includeLastKnown"] = 0
|
||||||
|
|
||||||
@ -2773,7 +2774,7 @@ class ChatController(args: Bundle) :
|
|||||||
currentConversation,
|
currentConversation,
|
||||||
chatMessage,
|
chatMessage,
|
||||||
conversationUser,
|
conversationUser,
|
||||||
hasChatPermission,
|
participantPermissions.hasChatPermission(),
|
||||||
ncApi
|
ncApi
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
@ -2801,7 +2802,7 @@ class ChatController(args: Bundle) :
|
|||||||
conversationUser,
|
conversationUser,
|
||||||
currentConversation,
|
currentConversation,
|
||||||
isShowMessageDeletionButton(message),
|
isShowMessageDeletionButton(message),
|
||||||
hasChatPermission,
|
participantPermissions.hasChatPermission(),
|
||||||
ncApi
|
ncApi
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
@ -2813,7 +2814,7 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteMessage(message: IMessage?) {
|
fun deleteMessage(message: IMessage?) {
|
||||||
if (!hasChatPermission) {
|
if (!participantPermissions.hasChatPermission()) {
|
||||||
Log.w(
|
Log.w(
|
||||||
TAG,
|
TAG,
|
||||||
"Deletion of message is skipped because of restrictions by permissions. " +
|
"Deletion of message is skipped because of restrictions by permissions. " +
|
||||||
@ -3143,7 +3144,7 @@ class ChatController(args: Bundle) :
|
|||||||
message.hasFileAttachment() -> false
|
message.hasFileAttachment() -> false
|
||||||
OBJECT_MESSAGE == message.message -> false
|
OBJECT_MESSAGE == message.message -> false
|
||||||
!CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "delete-messages") -> false
|
!CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "delete-messages") -> false
|
||||||
!hasChatPermission -> false
|
!participantPermissions.hasChatPermission() -> false
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -942,7 +942,7 @@ class ConversationsListController(bundle: Bundle) :
|
|||||||
if (showShareToScreen) {
|
if (showShareToScreen) {
|
||||||
if (hasChatPermission &&
|
if (hasChatPermission &&
|
||||||
!isReadOnlyConversation(selectedConversation!!) &&
|
!isReadOnlyConversation(selectedConversation!!) &&
|
||||||
!selectedConversation!!.shouldShowLobby(currentUser!!)
|
!shouldShowLobby(selectedConversation!!)
|
||||||
) {
|
) {
|
||||||
handleSharedData()
|
handleSharedData()
|
||||||
} else {
|
} 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 {
|
private fun isReadOnlyConversation(conversation: Conversation): Boolean {
|
||||||
return conversation.conversationReadOnlyState ===
|
return conversation.conversationReadOnlyState ===
|
||||||
Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY
|
Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY
|
||||||
|
@ -155,10 +155,6 @@ data class Conversation(
|
|||||||
return isParticipantOwnerOrModerator && !isLockedOneToOne(conversationUser)
|
return isParticipantOwnerOrModerator && !isLockedOneToOne(conversationUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldShowLobby(conversationUser: User): Boolean {
|
|
||||||
return LobbyState.LOBBY_STATE_MODERATORS_ONLY == lobbyState && !canModerate(conversationUser)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isLobbyViewApplicable(conversationUser: User): Boolean {
|
fun isLobbyViewApplicable(conversationUser: User): Boolean {
|
||||||
return !canModerate(conversationUser) &&
|
return !canModerate(conversationUser) &&
|
||||||
(type == ConversationType.ROOM_GROUP_CALL || type == ConversationType.ROOM_PUBLIC_CALL)
|
(type == ConversationType.ROOM_GROUP_CALL || type == ConversationType.ROOM_PUBLIC_CALL)
|
||||||
|
@ -38,20 +38,12 @@ class ParticipantPermissions(
|
|||||||
val isCustom = (conversation.permissions and CUSTOM) == CUSTOM
|
val isCustom = (conversation.permissions and CUSTOM) == CUSTOM
|
||||||
private val canStartCall = (conversation.permissions and START_CALL) == START_CALL
|
private val canStartCall = (conversation.permissions and START_CALL) == START_CALL
|
||||||
val canJoinCall = (conversation.permissions and JOIN_CALL) == JOIN_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 canPublishAudio = (conversation.permissions and PUBLISH_AUDIO) == PUBLISH_AUDIO
|
||||||
val canPublishVideo = (conversation.permissions and PUBLISH_VIDEO) == PUBLISH_VIDEO
|
val canPublishVideo = (conversation.permissions and PUBLISH_VIDEO) == PUBLISH_VIDEO
|
||||||
val canPublishScreen = (conversation.permissions and PUBLISH_SCREEN) == PUBLISH_SCREEN
|
val canPublishScreen = (conversation.permissions and PUBLISH_SCREEN) == PUBLISH_SCREEN
|
||||||
private val hasChatPermission = (conversation.permissions and CHAT) == CHAT
|
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 {
|
private fun hasConversationPermissions(): Boolean {
|
||||||
return CapabilitiesUtilNew.hasSpreedFeatureCapability(
|
return CapabilitiesUtilNew.hasSpreedFeatureCapability(
|
||||||
user,
|
user,
|
||||||
@ -59,6 +51,14 @@ class ParticipantPermissions(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun canIgnoreLobby(): Boolean {
|
||||||
|
if (hasConversationPermissions()) {
|
||||||
|
return canIgnoreLobby
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun canStartCall(): Boolean {
|
fun canStartCall(): Boolean {
|
||||||
return if (hasConversationPermissions()) {
|
return if (hasConversationPermissions()) {
|
||||||
canStartCall
|
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 {
|
companion object {
|
||||||
|
|
||||||
val TAG = ParticipantPermissions::class.simpleName
|
val TAG = ParticipantPermissions::class.simpleName
|
||||||
|
Loading…
Reference in New Issue
Block a user