2017-09-21 18:27:53 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-08-09 14:15:43 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2017-09-21 18:27:53 +00:00
|
|
|
|
2018-05-22 09:13:10 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
|
2017-09-21 18:27:53 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2018-06-18 19:27:04 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
2018-08-09 14:15:43 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.SafeData;
|
2018-08-01 15:09:24 +00:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2018-10-11 23:45:22 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2017-09-21 18:27:53 +00:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
|
|
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
|
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
import androidx.work.Data;
|
|
|
|
|
2018-10-11 23:45:22 +00:00
|
|
|
/**
|
|
|
|
* Use {@link MultiDeviceConfigurationUpdateJob}.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2017-09-21 18:27:53 +00:00
|
|
|
public class MultiDeviceReadReceiptUpdateJob extends ContextJob implements InjectableType {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
private static final String TAG = MultiDeviceReadReceiptUpdateJob.class.getSimpleName();
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
private static final String KEY_ENABLED = "enabled";
|
|
|
|
|
2017-09-21 18:27:53 +00:00
|
|
|
@Inject transient SignalServiceMessageSender messageSender;
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
private boolean enabled;
|
|
|
|
|
|
|
|
public MultiDeviceReadReceiptUpdateJob() {
|
|
|
|
super(null, null);
|
|
|
|
}
|
2017-09-21 18:27:53 +00:00
|
|
|
|
|
|
|
public MultiDeviceReadReceiptUpdateJob(Context context, boolean enabled) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withGroupId("__MULTI_DEVICE_READ_RECEIPT_UPDATE_JOB__")
|
2018-08-09 14:15:43 +00:00
|
|
|
.withNetworkRequirement()
|
2017-09-21 18:27:53 +00:00
|
|
|
.create());
|
|
|
|
|
|
|
|
this.enabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-09 14:15:43 +00:00
|
|
|
protected void initialize(@NonNull SafeData data) {
|
2018-10-02 19:31:12 +00:00
|
|
|
enabled = data.getBoolean(KEY_ENABLED);
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected @NonNull Data serialize(@NonNull Data.Builder dataBuilder) {
|
|
|
|
return dataBuilder.putBoolean(KEY_ENABLED, enabled).build();
|
|
|
|
}
|
2017-09-21 18:27:53 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException, UntrustedIdentityException {
|
2018-10-11 23:45:22 +00:00
|
|
|
if (!TextSecurePreferences.isMultiDevice(context)) {
|
|
|
|
Log.i(TAG, "Not multi device, aborting...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
messageSender.sendMessage(SignalServiceSyncMessage.forConfiguration(new ConfigurationMessage(Optional.of(enabled), Optional.absent())),
|
2018-05-22 09:13:10 +00:00
|
|
|
UnidentifiedAccessUtil.getAccessForSync(context));
|
2017-09-21 18:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
|
|
|
return e instanceof PushNetworkException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "**** Failed to synchronize read receipts state!");
|
|
|
|
}
|
|
|
|
}
|