Fix incorrect contacts being synced

This commit is contained in:
nielsandriesse 2020-07-17 15:06:16 +10:00
parent 68821b98aa
commit e3f107b00c
2 changed files with 9 additions and 7 deletions

View File

@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit
class BackgroundPollWorker : PersistentAlarmManagerListener() {
companion object {
private val pollInterval = TimeUnit.MINUTES.toMillis(30)
private val pollInterval = TimeUnit.MINUTES.toMillis(20)
@JvmStatic
fun schedule(context: Context) {

View File

@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.groups.GroupManager
import org.thoughtcrime.securesms.groups.GroupMessageProcessor
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob
import org.thoughtcrime.securesms.loki.utilities.ContactUtilities
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
import org.thoughtcrime.securesms.loki.utilities.recipient
import org.thoughtcrime.securesms.recipients.Recipient
@ -49,15 +50,16 @@ object SyncMessagesProtocol {
@JvmStatic
fun getContactsToSync(context: Context): List<ContactData> {
val allAddresses = ArrayList(DatabaseFactory.getRecipientDatabase(context).allAddresses)
val contacts = ContactUtilities.getAllContacts(context)
val result = mutableSetOf<ContactData>()
for (address in allAddresses) {
if (!shouldSyncContact(context, address.serialize())) { continue }
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(Recipient.from(context, address, false))
for (contact in contacts) {
val contactPublicKey = contact.recipient.address.serialize()
if (!shouldSyncContact(context, contactPublicKey)) { continue }
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient(context, contactPublicKey))
if (threadID < 0) { continue }
val displayName = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(address.serialize())
val displayName = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(contactPublicKey)
val contactData = ContactData(threadID, displayName)
contactData.numbers.add(NumberData("TextSecure", address.serialize()))
contactData.numbers.add(NumberData("TextSecure", contactPublicKey))
result.add(contactData)
}
return result.toList()