2016-11-20 22:50:41 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2016-11-20 22:50:41 +00:00
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
|
|
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup.Type;
|
|
|
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
|
|
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;
|
|
|
|
|
2016-11-20 22:50:41 +00:00
|
|
|
public class RequestGroupInfoJob extends ContextJob implements InjectableType {
|
|
|
|
|
|
|
|
private static final String TAG = RequestGroupInfoJob.class.getSimpleName();
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
private static final String KEY_SOURCE = "source";
|
|
|
|
private static final String KEY_GROUP_ID = "group_id";
|
|
|
|
|
2017-09-16 05:38:53 +00:00
|
|
|
@Inject transient SignalServiceMessageSender messageSender;
|
2016-11-20 22:50:41 +00:00
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
private String source;
|
|
|
|
private byte[] groupId;
|
|
|
|
|
|
|
|
public RequestGroupInfoJob() {
|
|
|
|
super(null, null);
|
|
|
|
}
|
2016-11-20 22:50:41 +00:00
|
|
|
|
|
|
|
public RequestGroupInfoJob(@NonNull Context context, @NonNull String source, @NonNull byte[] groupId) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
2018-08-09 14:15:43 +00:00
|
|
|
.withNetworkRequirement()
|
2016-11-20 22:50:41 +00:00
|
|
|
.withRetryCount(50)
|
|
|
|
.create());
|
|
|
|
|
|
|
|
this.source = source;
|
|
|
|
this.groupId = groupId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-09 14:15:43 +00:00
|
|
|
protected void initialize(@NonNull SafeData data) {
|
|
|
|
source = data.getString(KEY_SOURCE);
|
|
|
|
try {
|
|
|
|
groupId = GroupUtil.getDecodedId(data.getString(KEY_GROUP_ID));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected @NonNull Data serialize(@NonNull Data.Builder dataBuilder) {
|
|
|
|
return dataBuilder.putString(KEY_SOURCE, source)
|
|
|
|
.putString(KEY_GROUP_ID, GroupUtil.getEncodedId(groupId, false))
|
|
|
|
.build();
|
|
|
|
}
|
2016-11-20 22:50:41 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException, UntrustedIdentityException {
|
2017-09-16 05:38:53 +00:00
|
|
|
SignalServiceGroup group = SignalServiceGroup.newBuilder(Type.REQUEST_INFO)
|
|
|
|
.withId(groupId)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
|
|
|
|
.asGroupMessage(group)
|
|
|
|
.withTimestamp(System.currentTimeMillis())
|
|
|
|
.build();
|
2016-11-20 22:50:41 +00:00
|
|
|
|
|
|
|
messageSender.sendMessage(new SignalServiceAddress(source), message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
|
|
|
return e instanceof PushNetworkException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|