forked from upstream-mirrors/quik
Sync contacts for recipients when single conversation is synced
This commit is contained in:
@@ -28,9 +28,10 @@ import android.provider.Telephony.Sms
|
||||
import common.util.Keys
|
||||
import common.util.MessageUtils
|
||||
import common.util.extensions.*
|
||||
import common.util.filter.ContactFilter
|
||||
import data.mapper.CursorToConversation
|
||||
import data.mapper.CursorToPart
|
||||
import data.mapper.CursorToRecipient
|
||||
import data.model.Contact
|
||||
import data.model.Conversation
|
||||
import data.model.InboxItem
|
||||
import data.model.Message
|
||||
@@ -50,8 +51,8 @@ class MessageRepository @Inject constructor(
|
||||
private val context: Context,
|
||||
private val messageIds: Keys,
|
||||
private val cursorToConversation: CursorToConversation,
|
||||
private val cursorToPart: CursorToPart,
|
||||
private val cursorToRecipient: CursorToRecipient) {
|
||||
private val cursorToRecipient: CursorToRecipient,
|
||||
private val contactFilter: ContactFilter) {
|
||||
|
||||
fun getConversations(archived: Boolean = false): Flowable<List<InboxItem>> {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
@@ -455,15 +456,22 @@ class MessageRepository @Inject constructor(
|
||||
if (cursor.moveToFirst()) {
|
||||
conversation = cursorToConversation.map(cursor)
|
||||
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val contacts = realm.copyFromRealm(realm.where(Contact::class.java).findAll())
|
||||
|
||||
val recipients = conversation.recipients
|
||||
.map { recipient -> recipient.id.toString() }
|
||||
.map { id -> context.contentResolver.query(CursorToRecipient.URI, null, "_id = ?", arrayOf(id), null) }
|
||||
.map { recipientCursor -> recipientCursor.map { cursorToRecipient.map(recipientCursor) } }
|
||||
.flatten()
|
||||
.map { recipient ->
|
||||
recipient.apply { contact = contacts.firstOrNull { contactFilter.filter(it, recipient.address) } }
|
||||
}
|
||||
|
||||
conversation.recipients.clear()
|
||||
conversation.recipients.addAll(recipients)
|
||||
conversation.insertOrUpdate()
|
||||
realm.close()
|
||||
}
|
||||
|
||||
cursor.close()
|
||||
|
||||
Reference in New Issue
Block a user