Commit 36a7c349 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Load permissions just after loading list of chats

parent f0b85b9f
......@@ -70,10 +70,16 @@ class ChatRoomPresenter @Inject constructor(
private val stateChannel = Channel<State>()
private var lastState = manager.state
fun setupChatRoom() {
launchUI(strategy) {
val canPost = permissions.canPostToReadOnlyChannels()
view.onRoomChanged(canPost)
}
}
fun loadMessages(chatRoomId: String, chatRoomType: String, offset: Long = 0) {
this.chatRoomId = chatRoomId
this.chatRoomType = chatRoomType
println(permissions.canPostToReadOnlyChannels())
launchUI(strategy) {
view.showLoading()
try {
......
......@@ -120,4 +120,6 @@ interface ChatRoomView : LoadingView, MessageView {
* @param commands The list of available commands.
*/
fun populateCommandSuggestions(commands: List<CommandSuggestionViewModel>)
fun onRoomChanged(canPost: Boolean)
}
\ No newline at end of file
......@@ -124,11 +124,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
super.onViewCreated(view, savedInstanceState)
setupToolbar(chatRoomName)
presenter.setupChatRoom()
presenter.loadMessages(chatRoomId, chatRoomType)
presenter.loadChatRooms()
setupRecyclerView()
setupFab()
setupMessageComposer()
setupSuggestionsView()
setupActionSnackbar()
activity?.apply {
......@@ -227,6 +227,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override fun onRoomChanged(canPost: Boolean) {
setupMessageComposer()
}
private fun toggleNoChatView(size: Int) {
if (size == 0){
image_chat_icon.setVisible(true)
......
......@@ -66,12 +66,13 @@ class ChatRoomsPresenter @Inject constructor(
view.showLoading()
subscribeStatusChange()
try {
permissionsInteractor.saveAll(client.permissions())
// If we still don't have 'Store_Last_Message' setting, refresh the settings
if (!settings.hasShowLastMessage()) {
refreshSettingsInteractor.refresh(currentServer)
}
view.updateChatRooms(getUserChatRooms())
val permissions = retryIO { client.permissions() }
permissionsInteractor.saveAll(permissions)
} catch (ex: RocketChatException) {
ex.message?.let {
view.showMessage(it)
......@@ -96,6 +97,7 @@ class ChatRoomsPresenter @Inject constructor(
chatRoom.name
}
println("Owner -> ${chatRoom.user}")
navigator.toChatRoom(chatRoom.id, roomName,
chatRoom.type.toString(), chatRoom.readonly ?: false,
chatRoom.lastSeen ?: -1,
......
package chat.rocket.android.server.domain
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.common.model.User
import chat.rocket.core.model.Permission
import javax.inject.Inject
......@@ -57,12 +58,21 @@ class PermissionsInteractor @Inject constructor(
fun canPostToReadOnlyChannels(): Boolean {
val url = getCurrentServerUrl()!!
val currentUserRoles = localRepository.getCurrentUser(url)?.roles
val currentUserRoles = currentUser()?.roles
return permissionsRepository.get(url, POST_READONLY)?.let { permission ->
currentUserRoles?.isNotEmpty() == true && permission.roles.any {
currentUserRoles.contains(it)
}
} == true
} == true || isAdmin()
}
private fun currentUser(): User? {
val url = getCurrentServerUrl()!!
return localRepository.getCurrentUser(url)
}
private fun isAdmin(): Boolean {
return currentUser()?.roles?.find { it.equals("admin", ignoreCase = true) } != null
}
private fun getCurrentServerUrl(): String? {
......
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