mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
SDK will filter the chat rooms list itself, no need to do it in app
This commit is contained in:
parent
6d23402001
commit
c6fe442b09
1 changed files with 22 additions and 48 deletions
|
|
@ -117,36 +117,6 @@ class ConversationsListViewModel @UiThread constructor() : AbstractMainViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
|
||||||
private fun createConversationModel(chatRoom: ChatRoom): ConversationModel? {
|
|
||||||
val filter = currentFilter
|
|
||||||
if (filter.isEmpty()) {
|
|
||||||
return ConversationModel(chatRoom)
|
|
||||||
} else {
|
|
||||||
val participants = chatRoom.participants
|
|
||||||
val found = participants.find {
|
|
||||||
// Search in address but also in contact name if exists
|
|
||||||
val model =
|
|
||||||
coreContext.contactsManager.getContactAvatarModelForAddress(it.address)
|
|
||||||
model.contactName?.contains(
|
|
||||||
filter,
|
|
||||||
ignoreCase = true
|
|
||||||
) == true || it.address.asStringUriOnly().contains(
|
|
||||||
filter,
|
|
||||||
ignoreCase = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
found != null ||
|
|
||||||
chatRoom.peerAddress.asStringUriOnly().contains(filter, ignoreCase = true) ||
|
|
||||||
chatRoom.subject.orEmpty().contains(filter, ignoreCase = true)
|
|
||||||
) {
|
|
||||||
return ConversationModel(chatRoom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private fun computeChatRoomsList(filter: String) {
|
private fun computeChatRoomsList(filter: String) {
|
||||||
conversations.value.orEmpty().forEach(ConversationModel::destroy)
|
conversations.value.orEmpty().forEach(ConversationModel::destroy)
|
||||||
|
|
@ -159,13 +129,15 @@ class ConversationsListViewModel @UiThread constructor() : AbstractMainViewModel
|
||||||
var count = 0
|
var count = 0
|
||||||
|
|
||||||
val account = LinphoneUtils.getDefaultAccount()
|
val account = LinphoneUtils.getDefaultAccount()
|
||||||
val chatRooms = account?.chatRooms ?: coreContext.core.chatRooms
|
val chatRooms = if (filter.isEmpty()) {
|
||||||
for (chatRoom in chatRooms) {
|
account?.chatRooms
|
||||||
val model = createConversationModel(chatRoom)
|
} else {
|
||||||
if (model != null) {
|
account?.filterChatRooms(filter)
|
||||||
|
}
|
||||||
|
for (chatRoom in chatRooms.orEmpty()) {
|
||||||
|
val model = ConversationModel(chatRoom)
|
||||||
list.add(model)
|
list.add(model)
|
||||||
count += 1
|
count += 1
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 15) {
|
if (count == 15) {
|
||||||
conversations.postValue(list)
|
conversations.postValue(list)
|
||||||
|
|
@ -198,18 +170,20 @@ class ConversationsListViewModel @UiThread constructor() : AbstractMainViewModel
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentFilter.isNotEmpty()) {
|
||||||
|
val filteredRooms = defaultAccount.filterChatRooms(currentFilter)
|
||||||
|
val found = filteredRooms.find {
|
||||||
|
it == chatRoom
|
||||||
|
}
|
||||||
|
if (found == null) return
|
||||||
|
}
|
||||||
|
|
||||||
val newList = arrayListOf<ConversationModel>()
|
val newList = arrayListOf<ConversationModel>()
|
||||||
val model = createConversationModel(chatRoom)
|
val model = ConversationModel(chatRoom)
|
||||||
if (model != null) {
|
|
||||||
newList.add(model)
|
newList.add(model)
|
||||||
newList.addAll(currentList)
|
newList.addAll(currentList)
|
||||||
Log.i("$TAG Adding chat room to list")
|
Log.i("$TAG Adding chat room to list")
|
||||||
conversations.postValue(newList)
|
conversations.postValue(newList)
|
||||||
} else {
|
|
||||||
Log.w(
|
|
||||||
"$TAG A chat room was created but not displaying it because it doesn't match current filter"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue