mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 18:30:20 +01:00
Add ContactDiscovery abstraction for doing CDS refreshes.
This commit is contained in:
@@ -10,7 +10,7 @@ import android.os.Bundle;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.contacts.sync.ContactDiscovery;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
|
||||
@@ -47,7 +47,7 @@ public class ContactsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
if (!SignalStore.account().isRegistered()) {
|
||||
Log.i(TAG, "Not push registered. Just syncing contact info.");
|
||||
DirectoryHelper.syncRecipientInfoWithSystemContacts(context);
|
||||
ContactDiscovery.syncRecipientInfoWithSystemContacts(context);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ContactsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
if (unknownSystemNumbers.size() > FULL_SYNC_THRESHOLD) {
|
||||
Log.i(TAG, "There are " + unknownSystemNumbers.size() + " unknown contacts. Doing a full sync.");
|
||||
try {
|
||||
DirectoryHelper.refreshDirectory(context, true);
|
||||
ContactDiscovery.refreshAll(context, true);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
@@ -69,14 +69,14 @@ public class ContactsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
.map(s -> Recipient.external(getContext(), s))
|
||||
.toList();
|
||||
try {
|
||||
DirectoryHelper.refreshDirectoryFor(context, recipients, true);
|
||||
ContactDiscovery.refresh(context, recipients, true);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to refresh! Scheduling for later.", e);
|
||||
ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(true));
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "No new contacts. Just syncing system contact data.");
|
||||
DirectoryHelper.syncRecipientInfoWithSystemContacts(context);
|
||||
ContactDiscovery.syncRecipientInfoWithSystemContacts(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.thoughtcrime.securesms.contacts.sync
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.WorkerThread
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Methods for discovering which users are registered and marking them as such in the database.
|
||||
*/
|
||||
object ContactDiscovery {
|
||||
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
@WorkerThread
|
||||
fun refreshAll(context: Context, notifyOfNewUsers: Boolean) {
|
||||
DirectoryHelper.refreshAll(context, notifyOfNewUsers)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
@WorkerThread
|
||||
fun refresh(context: Context, recipients: List<Recipient>, notifyOfNewUsers: Boolean) {
|
||||
return DirectoryHelper.refresh(context, recipients, notifyOfNewUsers)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
@WorkerThread
|
||||
fun refresh(context: Context, recipient: Recipient, notifyOfNewUsers: Boolean): RecipientDatabase.RegisteredState {
|
||||
return DirectoryHelper.refresh(context, recipient, notifyOfNewUsers)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@WorkerThread
|
||||
fun syncRecipientInfoWithSystemContacts(context: Context) {
|
||||
DirectoryHelper.syncRecipientInfoWithSystemContacts(context)
|
||||
}
|
||||
}
|
||||
@@ -76,12 +76,12 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
/**
|
||||
* Manages all the stuff around determining if a user is registered or not.
|
||||
*/
|
||||
public class DirectoryHelper {
|
||||
class DirectoryHelper {
|
||||
|
||||
private static final String TAG = Log.tag(DirectoryHelper.class);
|
||||
|
||||
@WorkerThread
|
||||
public static void refreshDirectory(@NonNull Context context, boolean notifyOfNewUsers) throws IOException {
|
||||
static void refreshAll(@NonNull Context context, boolean notifyOfNewUsers) throws IOException {
|
||||
if (TextUtils.isEmpty(SignalStore.account().getE164())) {
|
||||
Log.w(TAG, "Have not yet set our own local number. Skipping.");
|
||||
return;
|
||||
@@ -108,7 +108,7 @@ public class DirectoryHelper {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static void refreshDirectoryFor(@NonNull Context context, @NonNull List<Recipient> recipients, boolean notifyOfNewUsers) throws IOException {
|
||||
static void refresh(@NonNull Context context, @NonNull List<Recipient> recipients, boolean notifyOfNewUsers) throws IOException {
|
||||
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
|
||||
|
||||
for (Recipient recipient : recipients) {
|
||||
@@ -130,7 +130,7 @@ public class DirectoryHelper {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static RegisteredState refreshDirectoryFor(@NonNull Context context, @NonNull Recipient recipient, boolean notifyOfNewUsers) throws IOException {
|
||||
static RegisteredState refresh(@NonNull Context context, @NonNull Recipient recipient, boolean notifyOfNewUsers) throws IOException {
|
||||
Stopwatch stopwatch = new Stopwatch("single");
|
||||
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
|
||||
RegisteredState originalRegisteredState = recipient.resolve().getRegistered();
|
||||
@@ -215,7 +215,7 @@ public class DirectoryHelper {
|
||||
/**
|
||||
* Reads the system contacts and copies over any matching data (like names) int our local store.
|
||||
*/
|
||||
public static void syncRecipientInfoWithSystemContacts(@NonNull Context context) {
|
||||
static void syncRecipientInfoWithSystemContacts(@NonNull Context context) {
|
||||
syncRecipientInfoWithSystemContacts(context, Collections.emptyMap());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user