forked from upstream-mirrors/quik
Do a better job at finding the right conversation
This commit is contained in:
@@ -178,12 +178,13 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
return Realm.getDefaultInstance().use { realm ->
|
return Realm.getDefaultInstance().use { realm ->
|
||||||
realm.where(Conversation::class.java)
|
realm.where(Conversation::class.java)
|
||||||
.findAll()
|
.findAll()
|
||||||
.firstOrNull { conversation ->
|
.asSequence()
|
||||||
conversation.recipients.size == recipients.size && conversation.recipients.map { it.address }.all { address ->
|
.filter { conversation -> conversation.recipients.size == recipients.size }
|
||||||
|
.find { conversation ->
|
||||||
|
conversation.recipients.map { it.address }.all { address ->
|
||||||
recipients.any { recipient -> phoneNumberUtils.compare(recipient, address) }
|
recipients.any { recipient -> phoneNumberUtils.compare(recipient, address) }
|
||||||
}
|
}
|
||||||
}
|
}?.id
|
||||||
?.id
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,13 +197,16 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getOrCreateConversation(addresses: List<String>): Conversation? {
|
override fun getOrCreateConversation(addresses: List<String>): Conversation? {
|
||||||
return tryOrNull { TelephonyCompat.getOrCreateThreadId(context, addresses.toSet()) }
|
if (addresses.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (getThreadId(addresses) ?: tryOrNull { TelephonyCompat.getOrCreateThreadId(context, addresses.toSet()) })
|
||||||
?.takeIf { threadId -> threadId != 0L }
|
?.takeIf { threadId -> threadId != 0L }
|
||||||
?.let { threadId ->
|
?.let { threadId ->
|
||||||
var conversation = getConversation(threadId)
|
getConversation(threadId)
|
||||||
if (conversation != null) conversation = Realm.getDefaultInstance().copyFromRealm(conversation)
|
?.let(Realm.getDefaultInstance()::copyFromRealm)
|
||||||
|
?: getConversationFromCp(threadId)
|
||||||
conversation ?: getConversationFromCp(threadId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user