forked from upstream-mirrors/quik
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> {
|
override fun searchConversations(query: CharSequence): List<SearchResult> {
|
||||||
val normalizedQuery = query.removeAccents()
|
val realm = Realm.getDefaultInstance()
|
||||||
val conversations = getConversationsSnapshot()
|
|
||||||
|
|
||||||
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)
|
.where(Message::class.java)
|
||||||
.beginGroup()
|
.beginGroup()
|
||||||
.contains("body", normalizedQuery, Case.INSENSITIVE)
|
.contains("body", normalizedQuery, Case.INSENSITIVE)
|
||||||
.or()
|
.or()
|
||||||
.contains("parts.text", normalizedQuery, Case.INSENSITIVE)
|
.contains("parts.text", normalizedQuery, Case.INSENSITIVE)
|
||||||
.endGroup()
|
.endGroup()
|
||||||
.findAll()
|
.findAll())
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.groupBy { message -> message.threadId }
|
.groupBy { message -> message.threadId }
|
||||||
.filter { (threadId, _) -> conversations.firstOrNull { it.id == threadId } != null }
|
.filter { (threadId, _) -> conversations.firstOrNull { it.id == threadId } != null }
|
||||||
@@ -131,10 +140,11 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
.sortedByDescending { result -> result.messages }
|
.sortedByDescending { result -> result.messages }
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
|
realm.close()
|
||||||
|
|
||||||
return conversations
|
return conversations
|
||||||
.filter { conversation -> conversationFilter.filter(conversation, normalizedQuery) }
|
.filter { conversation -> conversationFilter.filter(conversation, normalizedQuery) }
|
||||||
.map { conversation -> SearchResult(normalizedQuery, conversation, 0) }
|
.map { conversation -> SearchResult(normalizedQuery, conversation, 0) } + messagesByConversation
|
||||||
.plus(messagesByConversation)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBlockedConversations(): RealmResults<Conversation> {
|
override fun getBlockedConversations(): RealmResults<Conversation> {
|
||||||
|
|||||||
Reference in New Issue
Block a user