2016-08-26 23:53:23 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2017-08-22 01:37:39 +00:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.BlockedReader;
|
2016-08-26 23:53:23 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2018-06-18 19:27:04 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
|
2016-08-26 23:53:23 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
2017-08-01 15:56:00 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2016-08-26 23:53:23 +00:00
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
|
|
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
|
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
public class MultiDeviceBlockedUpdateJob extends MasterSecretJob implements InjectableType {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
private static final String TAG = MultiDeviceBlockedUpdateJob.class.getSimpleName();
|
|
|
|
|
2017-09-16 05:38:53 +00:00
|
|
|
@Inject transient SignalServiceMessageSender messageSender;
|
2016-08-26 23:53:23 +00:00
|
|
|
|
|
|
|
public MultiDeviceBlockedUpdateJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
|
|
|
.withRequirement(new MasterSecretRequirement(context))
|
|
|
|
.withGroupId(MultiDeviceBlockedUpdateJob.class.getSimpleName())
|
|
|
|
.withPersistence()
|
|
|
|
.create());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun(MasterSecret masterSecret)
|
|
|
|
throws IOException, UntrustedIdentityException
|
|
|
|
{
|
2017-09-16 05:38:53 +00:00
|
|
|
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
|
|
|
|
BlockedReader reader = database.readerForBlocked(database.getBlocked());
|
|
|
|
List<String> blocked = new LinkedList<>();
|
2016-08-26 23:53:23 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
Recipient recipient;
|
2016-08-26 23:53:23 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
while ((recipient = reader.getNext()) != null) {
|
|
|
|
if (!recipient.isGroupRecipient()) {
|
|
|
|
blocked.add(recipient.getAddress().serialize());
|
2016-08-26 23:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
messageSender.sendMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blocked)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetryThrowable(Exception exception) {
|
|
|
|
if (exception instanceof PushNetworkException) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|