Add download profile avatar job

This commit is contained in:
AsamK 2023-11-12 11:59:48 +01:00
parent ed11bf6368
commit d844e0f396
2 changed files with 25 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import org.asamk.signal.manager.api.PhoneNumberSharingMode;
import org.asamk.signal.manager.api.Profile; import org.asamk.signal.manager.api.Profile;
import org.asamk.signal.manager.api.TrustLevel; import org.asamk.signal.manager.api.TrustLevel;
import org.asamk.signal.manager.internal.SignalDependencies; import org.asamk.signal.manager.internal.SignalDependencies;
import org.asamk.signal.manager.jobs.DownloadProfileAvatarJob;
import org.asamk.signal.manager.storage.SignalAccount; import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.signal.libsignal.protocol.IdentityKey; import org.signal.libsignal.protocol.IdentityKey;
@ -276,7 +277,7 @@ public class StorageHelper {
if (profileKey != null) { if (profileKey != null) {
account.setProfileKey(profileKey); account.setProfileKey(profileKey);
final var avatarPath = accountRecord.getAvatarUrlPath().orElse(null); final var avatarPath = accountRecord.getAvatarUrlPath().orElse(null);
context.getProfileHelper().downloadProfileAvatar(account.getSelfRecipientId(), avatarPath, profileKey); context.getJobExecutor().enqueueJob(new DownloadProfileAvatarJob(avatarPath));
} }
} }

View file

@ -0,0 +1,23 @@
package org.asamk.signal.manager.jobs;
import org.asamk.signal.manager.helper.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DownloadProfileAvatarJob implements Job {
private static final Logger logger = LoggerFactory.getLogger(DownloadProfileAvatarJob.class);
private final String avatarPath;
public DownloadProfileAvatarJob(final String avatarPath) {
this.avatarPath = avatarPath;
}
@Override
public void run(Context context) {
logger.trace("Downloading profile avatar {}", avatarPath);
final var account = context.getAccount();
context.getProfileHelper()
.downloadProfileAvatar(account.getSelfRecipientId(), avatarPath, account.getProfileKey());
}
}