mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-19 20:38:53 +01:00
Sync contacts during message sync instead of after
This commit is contained in:
@@ -81,6 +81,7 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
.findAll()
|
.findAll()
|
||||||
.map { PersistedData(it.id, it.archived, it.blocked) }
|
.map { PersistedData(it.id, it.archived, it.blocked) }
|
||||||
|
|
||||||
|
realm.delete(Contact::class.java)
|
||||||
realm.delete(Conversation::class.java)
|
realm.delete(Conversation::class.java)
|
||||||
realm.delete(Message::class.java)
|
realm.delete(Message::class.java)
|
||||||
realm.delete(MmsPart::class.java)
|
realm.delete(MmsPart::class.java)
|
||||||
@@ -120,7 +121,16 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
// Sync recipients
|
// Sync recipients
|
||||||
cursorToRecipient.getRecipientCursor()?.use { recipientCursor ->
|
cursorToRecipient.getRecipientCursor()?.use { recipientCursor ->
|
||||||
val recipients = recipientCursor.map { cursor -> cursorToRecipient.map(cursor) }
|
val contacts = realm.copyToRealm(getContacts())
|
||||||
|
val recipients = recipientCursor
|
||||||
|
.map { cursor -> cursorToRecipient.map(cursor) }
|
||||||
|
.map { recipient ->
|
||||||
|
recipient.apply {
|
||||||
|
contact = contacts.firstOrNull { contact ->
|
||||||
|
contact.numbers.any { PhoneNumberUtils.compare(recipient.address, it.address) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
realm.insertOrUpdate(recipients)
|
realm.insertOrUpdate(recipients)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,8 +142,6 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
// Only delete this after the sync has successfully completed
|
// Only delete this after the sync has successfully completed
|
||||||
oldBlockedSenders.delete()
|
oldBlockedSenders.delete()
|
||||||
|
|
||||||
syncContacts()
|
|
||||||
|
|
||||||
syncProgress.onNext(SyncRepository.SyncProgress.Idle())
|
syncProgress.onNext(SyncRepository.SyncProgress.Idle())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,16 +191,7 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
override fun syncContacts() {
|
override fun syncContacts() {
|
||||||
// Load all the contacts
|
// Load all the contacts
|
||||||
var contacts = cursorToContact.getContactsCursor()
|
var contacts = getContacts()
|
||||||
?.map { cursor -> cursorToContact.map(cursor) }
|
|
||||||
?.groupBy { contact -> contact.lookupKey }
|
|
||||||
?.map { contacts ->
|
|
||||||
val allNumbers = contacts.value.map { it.numbers }.flatten()
|
|
||||||
contacts.value.first().apply {
|
|
||||||
numbers.clear()
|
|
||||||
numbers.addAll(allNumbers)
|
|
||||||
}
|
|
||||||
} ?: listOf()
|
|
||||||
|
|
||||||
Realm.getDefaultInstance()?.use { realm ->
|
Realm.getDefaultInstance()?.use { realm ->
|
||||||
val recipients = realm.where(Recipient::class.java).findAll()
|
val recipients = realm.where(Recipient::class.java).findAll()
|
||||||
@@ -217,4 +216,17 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getContacts(): List<Contact> {
|
||||||
|
return cursorToContact.getContactsCursor()
|
||||||
|
?.map { cursor -> cursorToContact.map(cursor) }
|
||||||
|
?.groupBy { contact -> contact.lookupKey }
|
||||||
|
?.map { contacts ->
|
||||||
|
val allNumbers = contacts.value.map { it.numbers }.flatten()
|
||||||
|
contacts.value.first().apply {
|
||||||
|
numbers.clear()
|
||||||
|
numbers.addAll(allNumbers)
|
||||||
|
}
|
||||||
|
} ?: listOf()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user