mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 19:18:52 +01:00
Include archived conversations in search results
This commit is contained in:
@@ -112,17 +112,26 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
}
|
||||
|
||||
override fun searchConversations(query: CharSequence): List<SearchResult> {
|
||||
val normalizedQuery = query.removeAccents()
|
||||
val conversations = getConversationsSnapshot()
|
||||
val realm = Realm.getDefaultInstance()
|
||||
|
||||
val messagesByConversation = Realm.getDefaultInstance()
|
||||
val normalizedQuery = query.removeAccents()
|
||||
val conversations = realm.copyFromRealm(realm
|
||||
.where(Conversation::class.java)
|
||||
.notEqualTo("id", 0L)
|
||||
.isNotNull("lastMessage")
|
||||
.equalTo("blocked", false)
|
||||
.isNotEmpty("recipients")
|
||||
.sort("pinned", Sort.DESCENDING, "lastMessage.date", Sort.DESCENDING)
|
||||
.findAll())
|
||||
|
||||
val messagesByConversation = realm.copyFromRealm(realm
|
||||
.where(Message::class.java)
|
||||
.beginGroup()
|
||||
.contains("body", normalizedQuery, Case.INSENSITIVE)
|
||||
.or()
|
||||
.contains("parts.text", normalizedQuery, Case.INSENSITIVE)
|
||||
.endGroup()
|
||||
.findAll()
|
||||
.findAll())
|
||||
.asSequence()
|
||||
.groupBy { message -> message.threadId }
|
||||
.filter { (threadId, _) -> conversations.firstOrNull { it.id == threadId } != null }
|
||||
@@ -131,10 +140,11 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.sortedByDescending { result -> result.messages }
|
||||
.toList()
|
||||
|
||||
realm.close()
|
||||
|
||||
return conversations
|
||||
.filter { conversation -> conversationFilter.filter(conversation, normalizedQuery) }
|
||||
.map { conversation -> SearchResult(normalizedQuery, conversation, 0) }
|
||||
.plus(messagesByConversation)
|
||||
.map { conversation -> SearchResult(normalizedQuery, conversation, 0) } + messagesByConversation
|
||||
}
|
||||
|
||||
override fun getBlockedConversations(): RealmResults<Conversation> {
|
||||
|
||||
Reference in New Issue
Block a user