mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 12:35:17 +00:00
42f1baaf61
We have to make some changes, and it's gotten to the point where maintaining it as a separate library is more hassle than it's worth, especially with Google releasing WorkManager as the preferred job scheduling library.
78 lines
2.8 KiB
Java
78 lines
2.8 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
import android.content.Context;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.BlockedReader;
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
|
import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
|
|
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
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();
|
|
|
|
@Inject transient SignalServiceMessageSender messageSender;
|
|
|
|
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
|
|
{
|
|
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
|
|
BlockedReader reader = database.readerForBlocked(database.getBlocked());
|
|
List<String> blocked = new LinkedList<>();
|
|
|
|
Recipient recipient;
|
|
|
|
while ((recipient = reader.getNext()) != null) {
|
|
if (!recipient.isGroupRecipient()) {
|
|
blocked.add(recipient.getAddress().serialize());
|
|
}
|
|
}
|
|
|
|
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() {
|
|
|
|
}
|
|
}
|