88 lines
2.8 KiB
Java
88 lines
2.8 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
import android.content.Context;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import org.signal.zkgroup.profiles.ProfileKey;
|
|
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
|
import org.thoughtcrime.securesms.jobmanager.Data;
|
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
|
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
|
import org.thoughtcrime.securesms.profiles.ProfileName;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
|
|
|
public final class ProfileUploadJob extends BaseJob {
|
|
|
|
public static final String KEY = "ProfileUploadJob";
|
|
|
|
private final Context context;
|
|
private final SignalServiceAccountManager accountManager;
|
|
|
|
public ProfileUploadJob() {
|
|
this(new Job.Parameters.Builder()
|
|
.addConstraint(NetworkConstraint.KEY)
|
|
.setQueue(KEY)
|
|
.setLifespan(Parameters.IMMORTAL)
|
|
.setMaxAttempts(Parameters.UNLIMITED)
|
|
.setMaxInstances(1)
|
|
.build());
|
|
}
|
|
|
|
private ProfileUploadJob(@NonNull Parameters parameters) {
|
|
super(parameters);
|
|
|
|
this.context = ApplicationDependencies.getApplication();
|
|
this.accountManager = ApplicationDependencies.getSignalServiceAccountManager();
|
|
}
|
|
|
|
@Override
|
|
protected void onRun() throws Exception {
|
|
ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
|
|
ProfileName profileName = TextSecurePreferences.getProfileName(context);
|
|
|
|
try (StreamDetails avatar = AvatarHelper.getSelfProfileAvatarStream(context)) {
|
|
if (FeatureFlags.VERSIONED_PROFILES) {
|
|
accountManager.setVersionedProfile(Recipient.self().getUuid().get(), profileKey, profileName.serialize(), avatar);
|
|
} else {
|
|
accountManager.setProfileName(profileKey, profileName.serialize());
|
|
accountManager.setProfileAvatar(profileKey, avatar);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected boolean onShouldRetry(@NonNull Exception e) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public @NonNull Data serialize() {
|
|
return Data.EMPTY;
|
|
}
|
|
|
|
@Override
|
|
public @NonNull String getFactoryKey() {
|
|
return KEY;
|
|
}
|
|
|
|
@Override
|
|
public void onFailure() {
|
|
}
|
|
|
|
public static class Factory implements Job.Factory {
|
|
|
|
@NonNull
|
|
@Override
|
|
public Job create(@NonNull Parameters parameters, @NonNull Data data) {
|
|
return new ProfileUploadJob(parameters);
|
|
}
|
|
}
|
|
}
|