2016-11-20 22:50:41 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
2018-05-22 09:13:10 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
|
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2016-11-20 22:50:41 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2019-03-28 15:56:35 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.Data;
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
2018-08-09 14:15:43 +00:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2018-05-22 09:13:10 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
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;
|
2019-03-28 15:56:35 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2016-11-20 22:50:41 +00:00
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
public class RequestGroupInfoJob extends BaseJob implements InjectableType {
|
2018-08-09 14:15:43 +00:00
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
public static final String KEY = "RequestGroupInfoJob";
|
2016-11-20 22:50:41 +00:00
|
|
|
|
2018-05-22 09:13:10 +00:00
|
|
|
@SuppressWarnings("unused")
|
2016-11-20 22:50:41 +00:00
|
|
|
private static final String TAG = RequestGroupInfoJob.class.getSimpleName();
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
private static final String KEY_SOURCE = "source";
|
|
|
|
private static final String KEY_GROUP_ID = "group_id";
|
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
@Inject SignalServiceMessageSender messageSender;
|
2016-11-20 22:50:41 +00:00
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
private String source;
|
|
|
|
private byte[] groupId;
|
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
public RequestGroupInfoJob(@NonNull String source, @NonNull byte[] groupId) {
|
|
|
|
this(new Job.Parameters.Builder()
|
|
|
|
.addConstraint(NetworkConstraint.KEY)
|
|
|
|
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
|
|
|
.setMaxAttempts(Parameters.UNLIMITED)
|
|
|
|
.build(),
|
|
|
|
source,
|
|
|
|
groupId);
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
2016-11-20 22:50:41 +00:00
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
private RequestGroupInfoJob(@NonNull Job.Parameters parameters, @NonNull String source, @NonNull byte[] groupId) {
|
|
|
|
super(parameters);
|
2016-11-20 22:50:41 +00:00
|
|
|
|
|
|
|
this.source = source;
|
|
|
|
this.groupId = groupId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-03-28 15:56:35 +00:00
|
|
|
public @NonNull Data serialize() {
|
|
|
|
return new Data.Builder().putString(KEY_SOURCE, source)
|
|
|
|
.putString(KEY_GROUP_ID, GroupUtil.getEncodedId(groupId, false))
|
|
|
|
.build();
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-03-28 15:56:35 +00:00
|
|
|
public @NonNull String getFactoryKey() {
|
|
|
|
return KEY;
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
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)
|
2019-12-11 23:07:17 +00:00
|
|
|
.withId(groupId, SignalServiceGroup.GroupType.SIGNAL)
|
2017-09-16 05:38:53 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
|
|
|
|
.asGroupMessage(group)
|
|
|
|
.withTimestamp(System.currentTimeMillis())
|
|
|
|
.build();
|
2016-11-20 22:50:41 +00:00
|
|
|
|
2019-06-24 06:00:15 +00:00
|
|
|
// TODO: Message ID
|
|
|
|
messageSender.sendMessage(0, new SignalServiceAddress(source),
|
2018-05-22 09:13:10 +00:00
|
|
|
UnidentifiedAccessUtil.getAccessFor(context, Recipient.from(context, Address.fromExternal(context, source), false)),
|
|
|
|
message);
|
2016-11-20 22:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public boolean onShouldRetry(@NonNull Exception e) {
|
2016-11-20 22:50:41 +00:00
|
|
|
return e instanceof PushNetworkException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
|
|
|
|
}
|
2019-03-28 15:56:35 +00:00
|
|
|
|
|
|
|
public static final class Factory implements Job.Factory<RequestGroupInfoJob> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull RequestGroupInfoJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
|
|
|
try {
|
|
|
|
return new RequestGroupInfoJob(parameters,
|
|
|
|
data.getString(KEY_SOURCE),
|
|
|
|
GroupUtil.getDecodedId(data.getString(KEY_GROUP_ID)));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 22:50:41 +00:00
|
|
|
}
|