rename canPostChatShareItemsDoReaction to hasChatPermission

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-05-10 16:51:47 +02:00
parent 7cf18923b5
commit bae65ebbe9
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
3 changed files with 29 additions and 15 deletions

View file

@ -274,6 +274,8 @@ class ChatController(args: Bundle) :
lateinit var mediaPlayerHandler: Handler
var currentlyPlayedVoiceMessage: ChatMessage? = null
var hasChatPermission: Boolean = false
init {
Log.d(TAG, "init ChatController: " + System.identityHashCode(this).toString())
@ -307,6 +309,9 @@ class ChatController(args: Bundle) :
}
this.voiceOnly = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false)
hasChatPermission =
AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission(conversationUser)
}
private fun getRoomInfo() {
@ -342,7 +347,8 @@ class ChatController(args: Bundle) :
setTitle()
try {
setupMentionAutocomplete()
checkReadOnlyState()
checkShowCallButtons()
checkShowMessageInputView()
checkLobbyState()
if (!inConversation) {
@ -1159,13 +1165,24 @@ class ChatController(args: Bundle) :
)
}
private fun checkReadOnlyState() {
private fun checkShowCallButtons() {
if (isAlive()) {
if (isReadOnlyConversation() || shouldShowLobby()) {
disableCallButtons()
binding.messageInputView.visibility = View.GONE
} else {
enableCallButtons()
}
}
}
private fun checkShowMessageInputView() {
if (isAlive()) {
if (isReadOnlyConversation()
|| shouldShowLobby()
|| !hasChatPermission
) {
binding.messageInputView.visibility = View.GONE
} else {
binding.messageInputView.visibility = View.VISIBLE
}
}
@ -2350,7 +2367,7 @@ class ChatController(args: Bundle) :
super.onPrepareOptionsMenu(menu)
conversationUser?.let {
if (CapabilitiesUtil.hasSpreedFeatureCapability(it, "read-only-rooms")) {
checkReadOnlyState()
checkShowCallButtons()
}
}
}
@ -2513,9 +2530,7 @@ class ChatController(args: Bundle) :
}
fun deleteMessage(message: IMessage?) {
if (!AttendeePermissionsUtil(currentConversation!!.permissions)
.canPostChatShareItemsDoReaction(conversationUser!!)
) {
if (!hasChatPermission) {
Log.e(
TAG, "Deletion of message is skipped because of restrictions by permissions. " +
"This method should not have been called!"
@ -2842,7 +2857,7 @@ class ChatController(args: Bundle) :
if (!CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "delete-messages")) return false
if (AttendeePermissionsUtil(currentConversation!!.permissions).canPostChatShareItemsDoReaction(conversationUser)) return true
if (!hasChatPermission) return false
return true
}

View file

@ -15,7 +15,7 @@ class AttendeePermissionsUtil(flag: Int) {
var canPublishAudio: Boolean = false
var canPublishVideo: Boolean = false
var canPublishScreen: Boolean = false
private var canPostChatShareItemsDoReaction: Boolean = false
private var hasChatPermission: Boolean = false
init {
isDefault = (flag and DEFAULT) == DEFAULT
@ -26,13 +26,12 @@ class AttendeePermissionsUtil(flag: Int) {
canPublishAudio = (flag and PUBLISH_AUDIO) == PUBLISH_AUDIO
canPublishVideo = (flag and PUBLISH_VIDEO) == PUBLISH_VIDEO
canPublishScreen = (flag and PUBLISH_SCREEN) == PUBLISH_SCREEN
canPostChatShareItemsDoReaction =
(flag and POST_CHAT_SHARE_ITEMS_DO_REACTIONS) == POST_CHAT_SHARE_ITEMS_DO_REACTIONS
hasChatPermission = (flag and CHAT) == CHAT
}
fun canPostChatShareItemsDoReaction(user: UserEntity): Boolean {
fun hasChatPermission(user: UserEntity): Boolean {
if (CapabilitiesUtil.hasSpreedFeatureCapability(user, "chat-permission")) {
return canPostChatShareItemsDoReaction
return hasChatPermission
}
// if capability is not available then the spreed version doesn't support to restrict this
return true
@ -48,6 +47,6 @@ class AttendeePermissionsUtil(flag: Int) {
const val PUBLISH_AUDIO = 16
const val PUBLISH_VIDEO = 32
const val PUBLISH_SCREEN = 64
const val POST_CHAT_SHARE_ITEMS_DO_REACTIONS = 128
const val CHAT = 128
}
}

View file

@ -23,6 +23,6 @@ class AttendeePermissionsUtilTest : TestCase() {
assertFalse(attendeePermissionsUtil.canPublishAudio)
assertFalse(attendeePermissionsUtil.canPublishVideo)
// canPostChatShareItemsDoReaction() is not possible to test because userEntity is necessary
// hasChatPermission() is not possible to test because userEntity is necessary
}
}