Fixed chat room UI not updated when kicked/invited back while in it

This commit is contained in:
Sylvain Berfini 2022-02-09 12:11:05 +01:00
parent eecbfccc2c
commit 7219cfbdf7

View file

@ -107,9 +107,19 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
stopVoiceRecordPlayer()
}
private val chatRoomListener: ChatRoomListenerStub = object : ChatRoomListenerStub() {
override fun onStateChanged(chatRoom: ChatRoom, state: ChatRoom.State) {
if (state == ChatRoom.State.Created || state == ChatRoom.State.Terminated) {
isReadOnly.value = chatRoom.hasBeenLeft()
}
}
}
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
init {
chatRoom.addListener(chatRoomListener)
attachments.value = arrayListOf()
attachFileEnabled.value = true
@ -138,6 +148,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
voiceRecordingPlayer.removeListener(playerListener)
}
chatRoom.removeListener(chatRoomListener)
scope.cancel()
super.onCleared()
}