Only refresh conversation list cell when a message is deleted, prevents blinking

This commit is contained in:
Sylvain Berfini 2025-05-29 11:40:42 +02:00
parent 08acbdf99f
commit e7f95adab9
6 changed files with 38 additions and 22 deletions

View file

@ -82,7 +82,7 @@ class ConversationEphemeralLifetimeFragment : SlidingPaneChildFragment() {
}
override fun onPause() {
sharedViewModel.newChatMessageEphemeralLifetimeToSet.value = Event(
sharedViewModel.newChatMessageEphemeralLifetimeToSetEvent.value = Event(
viewModel.currentlySelectedValue.value ?: 0L
)
super.onPause()

View file

@ -94,7 +94,6 @@ import org.linphone.utils.hideKeyboard
import org.linphone.utils.setKeyboardInsetListener
import org.linphone.utils.showKeyboard
import androidx.core.net.toUri
import androidx.lifecycle.observe
@UiThread
open class ConversationFragment : SlidingPaneChildFragment() {
@ -819,7 +818,7 @@ open class ConversationFragment : SlidingPaneChildFragment() {
val message = getString(R.string.conversation_message_deleted_toast)
val icon = R.drawable.trash_simple
(requireActivity() as GenericActivity).showGreenToast(message, icon)
sharedViewModel.forceRefreshConversations.value = Event(true)
sharedViewModel.updateConversationLastMessageEvent.value = Event(viewModel.conversationId)
}
}
@ -929,7 +928,7 @@ open class ConversationFragment : SlidingPaneChildFragment() {
}
}
sharedViewModel.forceRefreshConversationInfo.observe(viewLifecycleOwner) {
sharedViewModel.forceRefreshConversationInfoEvent.observe(viewLifecycleOwner) {
it.consume {
Log.i("$TAG Force refreshing conversation info")
viewModel.refresh()
@ -943,7 +942,7 @@ open class ConversationFragment : SlidingPaneChildFragment() {
}
}
sharedViewModel.newChatMessageEphemeralLifetimeToSet.observe(viewLifecycleOwner) {
sharedViewModel.newChatMessageEphemeralLifetimeToSetEvent.observe(viewLifecycleOwner) {
it.consume { ephemeralLifetime ->
Log.i(
"$TAG Setting [$ephemeralLifetime] as new ephemeral lifetime for messages"
@ -1190,14 +1189,14 @@ open class ConversationFragment : SlidingPaneChildFragment() {
Log.i("$TAG Muting conversation")
viewModel.mute()
popupWindow.dismiss()
sharedViewModel.forceRefreshDisplayedConversation.value = Event(true)
sharedViewModel.forceRefreshDisplayedConversationEvent.value = Event(true)
}
popupView.setUnmuteClickListener {
Log.i("$TAG Un-muting conversation")
viewModel.unMute()
popupWindow.dismiss()
sharedViewModel.forceRefreshDisplayedConversation.value = Event(true)
sharedViewModel.forceRefreshDisplayedConversationEvent.value = Event(true)
}
popupView.setConfigureEphemeralMessagesClickListener {

View file

@ -136,7 +136,7 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
viewModel.groupLeftEvent.observe(viewLifecycleOwner) {
it.consume {
Log.i("$TAG Group has been left, leaving conversation info...")
sharedViewModel.forceRefreshConversationInfo.value = Event(true)
sharedViewModel.forceRefreshConversationInfoEvent.value = Event(true)
goBack()
val message = getString(R.string.conversation_group_left_toast)
(requireActivity() as GenericActivity).showGreenToast(
@ -149,7 +149,7 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
viewModel.historyDeletedEvent.observe(viewLifecycleOwner) {
it.consume {
Log.i("$TAG History has been deleted, leaving conversation info...")
sharedViewModel.forceRefreshConversations.value = Event(true)
sharedViewModel.updateConversationLastMessageEvent.value = Event(viewModel.conversationId)
sharedViewModel.forceRefreshConversationEvents.value = Event(true)
goBack()
val message = getString(R.string.conversation_info_history_deleted_toast)
@ -180,7 +180,7 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
viewModel.infoChangedEvent.observe(viewLifecycleOwner) {
it.consume {
sharedViewModel.forceRefreshConversationInfo.postValue(Event(true))
sharedViewModel.forceRefreshConversationInfoEvent.postValue(Event(true))
}
}
@ -197,7 +197,7 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
}
}
sharedViewModel.newChatMessageEphemeralLifetimeToSet.observe(viewLifecycleOwner) {
sharedViewModel.newChatMessageEphemeralLifetimeToSetEvent.observe(viewLifecycleOwner) {
it.consume { ephemeralLifetime ->
Log.i(
"$TAG Setting [$ephemeralLifetime] as new ephemeral lifetime for messages"

View file

@ -274,13 +274,16 @@ class ConversationsListFragment : AbstractMainFragment() {
}
}
sharedViewModel.forceRefreshConversations.observe(viewLifecycleOwner) {
it.consume {
listViewModel.filter()
sharedViewModel.updateConversationLastMessageEvent.observe(viewLifecycleOwner) {
it.consume { conversationId ->
val model = listViewModel.conversations.value.orEmpty().find {
it.id == conversationId
}
model?.updateLastMessageInfo()
}
}
sharedViewModel.forceRefreshDisplayedConversation.observe(viewLifecycleOwner) {
sharedViewModel.forceRefreshDisplayedConversationEvent.observe(viewLifecycleOwner) {
it.consume {
val displayChatRoom = sharedViewModel.displayedChatRoom
if (displayChatRoom != null) {

View file

@ -20,8 +20,10 @@
package org.linphone.ui.main.chat.model
import android.text.Spannable
import android.text.SpannableStringBuilder
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.core.text.toSpannable
import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
@ -272,6 +274,13 @@ class ConversationModel
}
}
@UiThread
fun updateLastMessageInfo() {
coreContext.postOnCoreThread {
updateLastMessage()
}
}
@WorkerThread
private fun updateLastMessageStatus(message: ChatMessage) {
val isOutgoing = message.isOutgoing
@ -341,6 +350,11 @@ class ConversationModel
lastMessage = message
}
} else {
lastMessage = null
lastMessageTextSender.postValue("")
lastMessageContentIcon.postValue(0)
lastMessageText.postValue(SpannableStringBuilder("").toSpannable())
isLastMessageOutgoing.postValue(false)
Log.w("$TAG No last message to display for conversation [$id]")
}
}

View file

@ -138,15 +138,11 @@ class SharedMainViewModel
MutableLiveData<Event<Bundle>>()
}
val forceRefreshDisplayedConversation: MutableLiveData<Event<Boolean>> by lazy {
val forceRefreshDisplayedConversationEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val forceRefreshConversations: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val forceRefreshConversationInfo: MutableLiveData<Event<Boolean>> by lazy {
val forceRefreshConversationInfoEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -154,10 +150,14 @@ class SharedMainViewModel
MutableLiveData<Event<Boolean>>()
}
val newChatMessageEphemeralLifetimeToSet: MutableLiveData<Event<Long>> by lazy {
val newChatMessageEphemeralLifetimeToSetEvent: MutableLiveData<Event<Long>> by lazy {
MutableLiveData<Event<Long>>()
}
val updateConversationLastMessageEvent: MutableLiveData<Event<String>> by lazy {
MutableLiveData<Event<String>>()
}
val updateUnreadMessageCountForCurrentConversationEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}