mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Use newly added chatRoom.getAccount() to dynamically filter conversations
This commit is contained in:
parent
48d7976f9b
commit
337c103988
1 changed files with 12 additions and 16 deletions
|
|
@ -174,16 +174,12 @@ class ConversationsListViewModel
|
|||
|
||||
@WorkerThread
|
||||
private fun addChatRoom(chatRoom: ChatRoom) {
|
||||
val localAddress = chatRoom.localAddress
|
||||
val peerAddress = chatRoom.peerAddress
|
||||
|
||||
val identifier = chatRoom.identifier
|
||||
val chatRoomAccount = chatRoom.account
|
||||
val defaultAccount = LinphoneUtils.getDefaultAccount()
|
||||
if (defaultAccount == null ||
|
||||
defaultAccount.params.identityAddress?.weakEqual(localAddress) == false
|
||||
)
|
||||
{
|
||||
if (defaultAccount == null || chatRoomAccount == null || chatRoomAccount != defaultAccount) {
|
||||
Log.w(
|
||||
"$TAG Chat room with local address [${localAddress.asStringUriOnly()}] and peer address [${peerAddress.asStringUriOnly()}] was created but not displaying it because it doesn't belong to currently default account"
|
||||
"$TAG Chat room with identifier [$identifier] was created but not displaying it because it doesn't belong to currently default account"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
@ -191,16 +187,16 @@ class ConversationsListViewModel
|
|||
val hideEmptyChatRooms = coreContext.core.config.getBool("misc", "hide_empty_chat_rooms", true)
|
||||
// Hide empty chat rooms only applies to 1-1 conversations
|
||||
if (hideEmptyChatRooms && !LinphoneUtils.isChatRoomAGroup(chatRoom) && chatRoom.lastMessageInHistory == null) {
|
||||
Log.w("$TAG Chat room with local address [${localAddress.asStringUriOnly()}] and peer address [${peerAddress.asStringUriOnly()}] is empty, not adding it to match Core setting")
|
||||
Log.w("$TAG Chat room with identifier [$identifier] is empty, not adding it to match Core setting")
|
||||
return
|
||||
}
|
||||
|
||||
val currentList = conversations.value.orEmpty()
|
||||
val found = currentList.find {
|
||||
it.chatRoom.peerAddress.weakEqual(peerAddress)
|
||||
it.chatRoom.identifier == identifier
|
||||
}
|
||||
if (found != null) {
|
||||
Log.w("$TAG Created chat room with local address [${localAddress.asStringUriOnly()}] and peer address [${peerAddress.asStringUriOnly()}] is already in the list, skipping")
|
||||
Log.w("$TAG Created chat room with identifier [$identifier] is already in the list, skipping")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -216,27 +212,27 @@ class ConversationsListViewModel
|
|||
val model = ConversationModel(chatRoom)
|
||||
newList.add(model)
|
||||
newList.addAll(currentList)
|
||||
Log.i("$TAG Adding chat room with local address [${localAddress.asStringUriOnly()}] and peer address [${peerAddress.asStringUriOnly()}] to list")
|
||||
Log.i("$TAG Adding chat room with identifier [$identifier] to list")
|
||||
conversations.postValue(newList)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun removeChatRoom(chatRoom: ChatRoom) {
|
||||
val currentList = conversations.value.orEmpty()
|
||||
val peerAddress = chatRoom.peerAddress
|
||||
val identifier = chatRoom.identifier
|
||||
val found = currentList.find {
|
||||
it.chatRoom.peerAddress.weakEqual(peerAddress)
|
||||
it.chatRoom.identifier == identifier
|
||||
}
|
||||
if (found != null) {
|
||||
val newList = arrayListOf<ConversationModel>()
|
||||
newList.addAll(currentList)
|
||||
newList.remove(found)
|
||||
found.destroy()
|
||||
Log.i("$TAG Removing chat room [${peerAddress.asStringUriOnly()}] from list")
|
||||
Log.i("$TAG Removing chat room with identifier [$identifier] from list")
|
||||
conversations.postValue(newList)
|
||||
} else {
|
||||
Log.w(
|
||||
"$TAG Failed to find item in list matching deleted chat room peer address [${peerAddress.asStringUriOnly()}]"
|
||||
"$TAG Failed to find item in list matching deleted chat room identifier [$identifier]"
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue