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.Keys
|
||||||
import common.util.MessageUtils
|
import common.util.MessageUtils
|
||||||
import common.util.extensions.*
|
import common.util.extensions.*
|
||||||
|
import common.util.filter.ContactFilter
|
||||||
import data.mapper.CursorToConversation
|
import data.mapper.CursorToConversation
|
||||||
import data.mapper.CursorToPart
|
|
||||||
import data.mapper.CursorToRecipient
|
import data.mapper.CursorToRecipient
|
||||||
|
import data.model.Contact
|
||||||
import data.model.Conversation
|
import data.model.Conversation
|
||||||
import data.model.InboxItem
|
import data.model.InboxItem
|
||||||
import data.model.Message
|
import data.model.Message
|
||||||
@@ -50,8 +51,8 @@ class MessageRepository @Inject constructor(
|
|||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val messageIds: Keys,
|
private val messageIds: Keys,
|
||||||
private val cursorToConversation: CursorToConversation,
|
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>> {
|
fun getConversations(archived: Boolean = false): Flowable<List<InboxItem>> {
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
@@ -455,15 +456,22 @@ class MessageRepository @Inject constructor(
|
|||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
conversation = cursorToConversation.map(cursor)
|
conversation = cursorToConversation.map(cursor)
|
||||||
|
|
||||||
|
val realm = Realm.getDefaultInstance()
|
||||||
|
val contacts = realm.copyFromRealm(realm.where(Contact::class.java).findAll())
|
||||||
|
|
||||||
val recipients = conversation.recipients
|
val recipients = conversation.recipients
|
||||||
.map { recipient -> recipient.id.toString() }
|
.map { recipient -> recipient.id.toString() }
|
||||||
.map { id -> context.contentResolver.query(CursorToRecipient.URI, null, "_id = ?", arrayOf(id), null) }
|
.map { id -> context.contentResolver.query(CursorToRecipient.URI, null, "_id = ?", arrayOf(id), null) }
|
||||||
.map { recipientCursor -> recipientCursor.map { cursorToRecipient.map(recipientCursor) } }
|
.map { recipientCursor -> recipientCursor.map { cursorToRecipient.map(recipientCursor) } }
|
||||||
.flatten()
|
.flatten()
|
||||||
|
.map { recipient ->
|
||||||
|
recipient.apply { contact = contacts.firstOrNull { contactFilter.filter(it, recipient.address) } }
|
||||||
|
}
|
||||||
|
|
||||||
conversation.recipients.clear()
|
conversation.recipients.clear()
|
||||||
conversation.recipients.addAll(recipients)
|
conversation.recipients.addAll(recipients)
|
||||||
conversation.insertOrUpdate()
|
conversation.insertOrUpdate()
|
||||||
|
realm.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user