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( ...@@ -116,11 +116,12 @@ class ChatRoomPresenter @Inject constructor(
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) { chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName) client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else emptyList() } else emptyList()
val canPost = isOwnerOrMod() || permissions.canPostToReadOnlyChannels() val userCanMod = isOwnerOrMod()
val userCanPost = userCanMod || permissions.canPostToReadOnlyChannels()
chatIsBroadcast = chatRoomsInteractor.getById(currentServer, roomId)?.run { chatIsBroadcast = chatRoomsInteractor.getById(currentServer, roomId)?.run {
broadcast broadcast
} ?: false } ?: false
view.onRoomUpdated(canPost, chatIsBroadcast) view.onRoomUpdated(userCanPost, chatIsBroadcast, userCanMod)
loadMessages(roomId, roomType) loadMessages(roomId, roomType)
chatRoomMessage?.let { messageHelper.messageIdFromPermalink(it) }?.let { messageId -> chatRoomMessage?.let { messageHelper.messageIdFromPermalink(it) }?.let { messageId ->
val name = messageHelper.roomNameFromPermalink(chatRoomMessage) val name = messageHelper.roomNameFromPermalink(chatRoomMessage)
...@@ -130,9 +131,9 @@ class ChatRoomPresenter @Inject constructor( ...@@ -130,9 +131,9 @@ class ChatRoomPresenter @Inject constructor(
} }
private fun isOwnerOrMod(): Boolean { 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" it == "owner" || it == "moderator"
} ?: false == true } ?: false
} }
fun loadMessages(chatRoomId: String, chatRoomType: String, offset: Long = 0) { fun loadMessages(chatRoomId: String, chatRoomType: String, offset: Long = 0) {
......
...@@ -139,7 +139,7 @@ interface ChatRoomView : LoadingView, MessageView { ...@@ -139,7 +139,7 @@ interface ChatRoomView : LoadingView, MessageView {
/** /**
* Communicate whether it's a broadcast channel and if current user can post to it. * 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 * 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 ...@@ -284,10 +284,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
} }
override fun onRoomUpdated(canPost: Boolean, broadcastChannel: Boolean) { override fun onRoomUpdated(userCanPost: Boolean, channelIsBroadcast: Boolean, userCanMod: Boolean) {
setupMessageComposer(isChatRoomOwner || canPost) setupMessageComposer(isChatRoomOwner || userCanPost)
isBroadcastChannel = broadcastChannel isBroadcastChannel = channelIsBroadcast
if (isBroadcastChannel) activity?.invalidateOptionsMenu() if (isBroadcastChannel && !userCanMod) activity?.invalidateOptionsMenu()
} }
override fun openDirectMessage(chatRoom: ChatRoom, permalink: String) { override fun openDirectMessage(chatRoom: ChatRoom, permalink: String) {
...@@ -660,10 +660,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -660,10 +660,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_join_chat.setVisible(true) button_join_chat.setVisible(true)
button_join_chat.setOnClickListener { presenter.joinChat(chatRoomId) } button_join_chat.setOnClickListener { presenter.joinChat(chatRoomId) }
} else { } else {
// if (chatRoomMessage.orEmpty().isNotEmpty()) {
// text_message.textContent = chatRoomMessage!!
// text_message.setSelection(chatRoomMessage!!.length)
// }
button_send.alpha = 0f button_send.alpha = 0f
button_send.setVisible(false) button_send.setVisible(false)
button_show_attachment_options.alpha = 1f 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