2020-10-14 17:43:49 +00:00
|
|
|
package org.thoughtcrime.securesms.migrations;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2020-12-04 23:31:58 +00:00
|
|
|
import org.signal.core.util.logging.Log;
|
2022-03-18 17:33:23 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.sync.ContactDiscovery;
|
2020-10-14 17:43:49 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.Data;
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
|
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does a full directory refresh.
|
|
|
|
*/
|
|
|
|
public final class DirectoryRefreshMigrationJob extends MigrationJob {
|
|
|
|
|
|
|
|
private static final String TAG = Log.tag(DirectoryRefreshMigrationJob.class);
|
|
|
|
|
|
|
|
public static final String KEY = "DirectoryRefreshMigrationJob";
|
|
|
|
|
|
|
|
DirectoryRefreshMigrationJob() {
|
|
|
|
this(new Parameters.Builder().build());
|
|
|
|
}
|
|
|
|
|
|
|
|
private DirectoryRefreshMigrationJob(@NonNull Parameters parameters) {
|
|
|
|
super(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUiBlocking() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull String getFactoryKey() {
|
|
|
|
return KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void performMigration() throws IOException {
|
2021-11-17 20:08:28 +00:00
|
|
|
if (!SignalStore.account().isRegistered() ||
|
2020-10-14 17:43:49 +00:00
|
|
|
!SignalStore.registrationValues().isRegistrationComplete() ||
|
2021-11-17 20:08:28 +00:00
|
|
|
SignalStore.account().getAci() == null)
|
2020-10-14 17:43:49 +00:00
|
|
|
{
|
|
|
|
Log.w(TAG, "Not registered! Skipping.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-18 17:33:23 +00:00
|
|
|
ContactDiscovery.refreshAll(context, true);
|
2020-10-14 17:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
boolean shouldRetry(@NonNull Exception e) {
|
|
|
|
return e instanceof IOException;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Factory implements Job.Factory<DirectoryRefreshMigrationJob> {
|
|
|
|
@Override
|
|
|
|
public @NonNull DirectoryRefreshMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
|
|
|
return new DirectoryRefreshMigrationJob(parameters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|