Fixed chat rooms list cells not updating contacts info
This commit is contained in:
parent
f3a6480278
commit
122581fd68
2 changed files with 28 additions and 3 deletions
|
@ -31,6 +31,7 @@ import org.linphone.activities.main.adapters.SelectionListAdapter
|
|||
import org.linphone.activities.main.chat.data.ChatRoomData
|
||||
import org.linphone.activities.main.viewmodels.ListTopBarViewModel
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ChatRoomListCellBinding
|
||||
import org.linphone.utils.Event
|
||||
|
||||
|
@ -69,6 +70,19 @@ class ChatRoomsListAdapter(
|
|||
chatRoomData.update()
|
||||
data = chatRoomData
|
||||
|
||||
chatRoomData.contactNewlyFoundEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
// Post to prevent IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
|
||||
binding.root.post {
|
||||
try {
|
||||
notifyItemChanged(bindingAdapterPosition)
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Chat Rooms Adapter] Can't notify item [$bindingAdapterPosition] has changed: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
// This is for item selection through ListTopBarFragment
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.linphone.contact.ContactsUpdatedListenerStub
|
|||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.TimestampUtils
|
||||
|
||||
|
@ -81,12 +82,16 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
|||
chatRoom.hasCapability(ChatRoomCapabilities.Encrypted.toInt())
|
||||
}
|
||||
|
||||
val contactNewlyFoundEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
private val contactsListener = object : ContactsUpdatedListenerStub() {
|
||||
override fun onContactsUpdated() {
|
||||
if (oneToOneChatRoom && contact.value == null) {
|
||||
if (contact.value == null && oneToOneChatRoom) {
|
||||
searchMatchingContact()
|
||||
}
|
||||
if (!oneToOneChatRoom && contact.value != null) {
|
||||
if (!oneToOneChatRoom) {
|
||||
formatLastMessage(chatRoom.lastMessageInHistory)
|
||||
}
|
||||
}
|
||||
|
@ -161,11 +166,17 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
|||
if (remoteAddress != null) {
|
||||
val friend = coreContext.contactsManager.findContactByAddress(remoteAddress)
|
||||
if (friend != null) {
|
||||
val newlyFound = contact.value == null
|
||||
|
||||
contact.value = friend!!
|
||||
presenceStatus.value = friend.consolidatedPresence
|
||||
friend.addListener {
|
||||
presenceStatus.value = it.consolidatedPresence
|
||||
}
|
||||
|
||||
if (newlyFound) {
|
||||
contactNewlyFoundEvent.value = Event(true)
|
||||
}
|
||||
} else {
|
||||
displayName.value = LinphoneUtils.getDisplayName(remoteAddress)
|
||||
}
|
||||
|
@ -198,7 +209,7 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
|||
}
|
||||
computeLastMessageImdnIcon(msg)
|
||||
|
||||
if (!chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||
if (!oneToOneChatRoom) {
|
||||
val sender: String =
|
||||
coreContext.contactsManager.findContactByAddress(msg.fromAddress)?.name
|
||||
?: LinphoneUtils.getDisplayName(msg.fromAddress)
|
||||
|
|
Loading…
Reference in a new issue