Commit c765ed8e authored by Leonardo Aramaki's avatar Leonardo Aramaki

Properly check if user has owner or moderator roles at channels

parent 64762358
......@@ -116,11 +116,12 @@ class ChatRoomPresenter @Inject constructor(
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else emptyList()
val canPost = isOwnerOrMod() || permissions.canPostToReadOnlyChannels()
val userCanMod = isOwnerOrMod()
val userCanPost = userCanMod || permissions.canPostToReadOnlyChannels()
chatIsBroadcast = chatRoomsInteractor.getById(currentServer, roomId)?.run {
broadcast
} ?: false
view.onRoomUpdated(canPost, chatIsBroadcast)
view.onRoomUpdated(userCanPost, chatIsBroadcast, userCanMod)
loadMessages(roomId, roomType)
chatRoomMessage?.let { messageHelper.messageIdFromPermalink(it) }?.let { messageId ->
val name = messageHelper.roomNameFromPermalink(chatRoomMessage)
......@@ -130,9 +131,9 @@ class ChatRoomPresenter @Inject constructor(
}
private fun isOwnerOrMod(): Boolean {
return chatRoles.firstOrNull { it.user.username == currentLoggedUsername }?.roles?.firstOrNull {
return chatRoles.firstOrNull { it.user.username == currentLoggedUsername }?.roles?.any {
it == "owner" || it == "moderator"
} ?: false == true
} ?: false
}
fun loadMessages(chatRoomId: String, chatRoomType: String, offset: Long = 0) {
......
......@@ -139,7 +139,7 @@ interface ChatRoomView : LoadingView, MessageView {
/**
* Communicate whether it's a broadcast channel and if current user can post to it.
*/
fun onRoomUpdated(canPost: Boolean, broadcastChannel: Boolean)
fun onRoomUpdated(userCanPost: Boolean, channelIsBroadcast: Boolean, userIsModerator: Boolean)
/**
* Open a DM with the user in the given [chatRoom] and pass the [permalink] for the message
......
......@@ -284,10 +284,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override fun onRoomUpdated(canPost: Boolean, broadcastChannel: Boolean) {
setupMessageComposer(isChatRoomOwner || canPost)
isBroadcastChannel = broadcastChannel
if (isBroadcastChannel) activity?.invalidateOptionsMenu()
override fun onRoomUpdated(userCanPost: Boolean, channelIsBroadcast: Boolean, userCanMod: Boolean) {
setupMessageComposer(isChatRoomOwner || userCanPost)
isBroadcastChannel = channelIsBroadcast
if (isBroadcastChannel && !userCanMod) activity?.invalidateOptionsMenu()
}
override fun openDirectMessage(chatRoom: ChatRoom, permalink: String) {
......@@ -660,10 +660,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_join_chat.setVisible(true)
button_join_chat.setOnClickListener { presenter.joinChat(chatRoomId) }
} else {
// if (chatRoomMessage.orEmpty().isNotEmpty()) {
// text_message.textContent = chatRoomMessage!!
// text_message.setSelection(chatRoomMessage!!.length)
// }
button_send.alpha = 0f
button_send.setVisible(false)
button_show_attachment_options.alpha = 1f
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment