2017-09-16 05:38:53 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
|
|
|
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;
|
2018-08-01 15:09:24 +00:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2017-09-16 05:38:53 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
|
|
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
|
|
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
public class SendReadReceiptJob extends ContextJob implements InjectableType {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
private static final String TAG = SendReadReceiptJob.class.getSimpleName();
|
|
|
|
|
|
|
|
@Inject transient SignalServiceMessageSender messageSender;
|
|
|
|
|
|
|
|
private final String address;
|
|
|
|
private final List<Long> messageIds;
|
|
|
|
private final long timestamp;
|
|
|
|
|
|
|
|
public SendReadReceiptJob(Context context, Address address, List<Long> messageIds) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
|
|
|
.withPersistence()
|
|
|
|
.create());
|
|
|
|
|
|
|
|
this.address = address.serialize();
|
|
|
|
this.messageIds = messageIds;
|
|
|
|
this.timestamp = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException, UntrustedIdentityException {
|
|
|
|
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) return;
|
|
|
|
|
|
|
|
SignalServiceAddress remoteAddress = new SignalServiceAddress(address);
|
|
|
|
SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ, messageIds, timestamp);
|
|
|
|
|
|
|
|
messageSender.sendReceipt(remoteAddress, receiptMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
|
|
|
if (e instanceof PushNetworkException) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "Failed to send read receipts to: " + address);
|
|
|
|
}
|
|
|
|
}
|