diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index feaf664cd1..de46dcfdd4 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -409,7 +409,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje if (avatar != null) { Log.d("Loki", "Start uploading profile photo"); LokiStorageAPI storageAPI = LokiStorageAPI.shared; - LokiDotNetAPI.UploadResult result = storageAPI.uploadProfilePhoto(storageAPI.getServer(), avatarBytes); + LokiDotNetAPI.UploadResult result = storageAPI.uploadProfilePhoto(storageAPI.getServer(), profileKey, avatar); Log.d("Loki", "Profile photo uploaded, the url is " + result.getUrl()); TextSecurePreferences.setProfileAvatarUrl(CreateProfileActivity.this, result.getUrl()); } else { diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 1df6ca9515..499b116472 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -317,7 +317,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType { }); } - // TODO: Deleting the display name + // Loki - Store profile avatar + if (content.senderProfileAvatarUrl.isPresent()) { + handleProfileAvatar(content, content.senderProfileAvatarUrl.get()); + } + if (content.getPairingAuthorisation().isPresent()) { handlePairingMessage(content.getPairingAuthorisation().get(), envelope, content); } else if (content.getDataMessage().isPresent()) { @@ -1082,6 +1086,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType { return authorisation.verify(); } + private void handleProfileAvatar(SignalServiceContent content, String url) { + Recipient primaryDevice = getPrimaryDeviceRecipient(content.getSender()); + ApplicationContext.getInstance(context).getJobManager().add(new RetrieveProfileAvatarJob(primaryDevice, url)); + } + private void handlePairingMessage(@NonNull PairingAuthorisation authorisation, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) { String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context); if (authorisation.getType() == PairingAuthorisation.Type.REQUEST) { diff --git a/src/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java b/src/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java index 45f551d5aa..e6f281d565 100644 --- a/src/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java +++ b/src/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java @@ -50,6 +50,7 @@ public class RetrieveProfileAvatarJob extends BaseJob implements InjectableType .addConstraint(NetworkConstraint.KEY) .setLifespan(TimeUnit.HOURS.toMillis(1)) .setMaxInstances(1) + .setMaxAttempts(2) .build(), recipient, profileAvatar); @@ -99,8 +100,8 @@ public class RetrieveProfileAvatarJob extends BaseJob implements InjectableType File downloadDestination = File.createTempFile("avatar", "jpg", context.getCacheDir()); try { - InputStream avatarStream = receiver.retrieveProfileAvatar(profileAvatar, downloadDestination, profileKey, MAX_PROFILE_SIZE_BYTES); - File decryptDestination = File.createTempFile("avatar", "jpg", context.getCacheDir()); + InputStream avatarStream = receiver.retrieveProfileAvatar(profileAvatar, downloadDestination, profileKey, MAX_PROFILE_SIZE_BYTES); + File decryptDestination = File.createTempFile("avatar", "jpg", context.getCacheDir()); Util.copy(avatarStream, new FileOutputStream(decryptDestination)); decryptDestination.renameTo(AvatarHelper.getAvatarFile(context, recipient.getAddress()));