Fixed muted state in conversations list cell when updated from conversation

This commit is contained in:
Sylvain Berfini 2024-09-03 16:49:28 +02:00
parent 4cbad5308c
commit 6893d35a93
4 changed files with 25 additions and 0 deletions

View file

@ -1049,12 +1049,14 @@ open class ConversationFragment : SlidingPaneChildFragment() {
Log.i("$TAG Muting conversation")
viewModel.mute()
popupWindow.dismiss()
sharedViewModel.forceRefreshDisplayedConversation.value = Event(true)
}
popupView.setUnmuteClickListener {
Log.i("$TAG Un-muting conversation")
viewModel.unMute()
popupWindow.dismiss()
sharedViewModel.forceRefreshDisplayedConversation.value = Event(true)
}
popupView.setConfigureEphemeralMessagesClickListener {

View file

@ -281,6 +281,18 @@ class ConversationsListFragment : AbstractMainFragment() {
}
}
sharedViewModel.forceRefreshDisplayedConversation.observe(viewLifecycleOwner) {
it.consume {
val displayChatRoom = sharedViewModel.displayedChatRoom
if (displayChatRoom != null) {
val found = listViewModel.conversations.value.orEmpty().find { model ->
model.chatRoom == displayChatRoom
}
found?.updateMuteState()
}
}
}
sharedViewModel.updateUnreadMessageCountForCurrentConversationEvent.observe(
viewLifecycleOwner
) {

View file

@ -206,6 +206,13 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
}
}
@UiThread
fun updateMuteState() {
coreContext.postOnCoreThread {
isMuted.postValue(chatRoom.muted)
}
}
@UiThread
fun toggleMute() {
coreContext.postOnCoreThread {

View file

@ -127,6 +127,10 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Bundle>>()
}
val forceRefreshDisplayedConversation: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val forceRefreshConversations: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}