mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 07:48:34 +00:00
Allow RetrieveProfileJob to be used for self.
This commit is contained in:
parent
2d60d5fb1f
commit
f5e6fd6340
@ -1842,7 +1842,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient.get()));
|
ApplicationDependencies.getJobManager().add(RetrieveProfileJob.forRecipient(recipient.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRecipientChanged(@NonNull Recipient recipient) {
|
private void onRecipientChanged(@NonNull Recipient recipient) {
|
||||||
|
@ -1274,7 +1274,7 @@ public final class PushProcessMessageJob extends BaseJob {
|
|||||||
|
|
||||||
if (messageProfileKey != null) {
|
if (messageProfileKey != null) {
|
||||||
if (database.setProfileKey(recipient.getId(), messageProfileKey)) {
|
if (database.setProfileKey(recipient.getId(), messageProfileKey)) {
|
||||||
ApplicationDependencies.getJobManager().add(new RetrieveProfileJob(recipient));
|
ApplicationDependencies.getJobManager().add(RetrieveProfileJob.forRecipient(recipient));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Ignored invalid profile key seen in message");
|
Log.w(TAG, "Ignored invalid profile key seen in message");
|
||||||
|
@ -38,8 +38,9 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a users profile and sets the appropriate local fields. If fetching the profile of the
|
* Retrieves a users profile and sets the appropriate local fields.
|
||||||
* local user, use {@link RefreshOwnProfileJob} instead.
|
* <p>
|
||||||
|
* Recipient can be self if you use {@link #forRecipient} and it will delegate to {@link RefreshOwnProfileJob}.
|
||||||
*/
|
*/
|
||||||
public class RetrieveProfileJob extends BaseJob {
|
public class RetrieveProfileJob extends BaseJob {
|
||||||
|
|
||||||
@ -49,24 +50,36 @@ public class RetrieveProfileJob extends BaseJob {
|
|||||||
|
|
||||||
private static final String KEY_RECIPIENT = "recipient";
|
private static final String KEY_RECIPIENT = "recipient";
|
||||||
|
|
||||||
private final Recipient recipient;
|
private final RecipientId recipientId;
|
||||||
|
|
||||||
public RetrieveProfileJob(@NonNull Recipient recipient) {
|
public static Job forRecipient(@NonNull Recipient recipient) {
|
||||||
|
return forRecipient(recipient.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Job forRecipient(@NonNull RecipientId recipientId) {
|
||||||
|
if (Recipient.self().getId().equals(recipientId)) {
|
||||||
|
return new RefreshOwnProfileJob();
|
||||||
|
} else {
|
||||||
|
return new RetrieveProfileJob(recipientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RetrieveProfileJob(@NonNull RecipientId recipientId) {
|
||||||
this(new Job.Parameters.Builder()
|
this(new Job.Parameters.Builder()
|
||||||
.addConstraint(NetworkConstraint.KEY)
|
.addConstraint(NetworkConstraint.KEY)
|
||||||
.setMaxAttempts(3)
|
.setMaxAttempts(3)
|
||||||
.build(),
|
.build(),
|
||||||
recipient);
|
recipientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RetrieveProfileJob(@NonNull Job.Parameters parameters, @NonNull Recipient recipient) {
|
private RetrieveProfileJob(@NonNull Job.Parameters parameters, @NonNull RecipientId recipientId) {
|
||||||
super(parameters);
|
super(parameters);
|
||||||
this.recipient = recipient;
|
this.recipientId = recipientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Data serialize() {
|
public @NonNull Data serialize() {
|
||||||
return new Data.Builder().putString(KEY_RECIPIENT, recipient.getId().serialize()).build();
|
return new Data.Builder().putString(KEY_RECIPIENT, recipientId.serialize()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -76,9 +89,9 @@ public class RetrieveProfileJob extends BaseJob {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws IOException {
|
public void onRun() throws IOException {
|
||||||
Log.i(TAG, "Retrieving profile of " + recipient.getId());
|
Log.i(TAG, "Retrieving profile of " + recipientId);
|
||||||
|
|
||||||
Recipient resolved = recipient.resolve();
|
Recipient resolved = Recipient.resolved(recipientId);
|
||||||
|
|
||||||
if (resolved.isGroup()) handleGroupRecipient(resolved);
|
if (resolved.isGroup()) handleGroupRecipient(resolved);
|
||||||
else handleIndividualRecipient(resolved);
|
else handleIndividualRecipient(resolved);
|
||||||
@ -248,7 +261,7 @@ public class RetrieveProfileJob extends BaseJob {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull RetrieveProfileJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
public @NonNull RetrieveProfileJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
||||||
return new RetrieveProfileJob(parameters, Recipient.resolved(RecipientId.from(data.getString(KEY_RECIPIENT))));
|
return new RetrieveProfileJob(parameters, RecipientId.from(data.getString(KEY_RECIPIENT)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user