Added profile downloading.

This commit is contained in:
Mikunj 2019-11-26 10:33:34 +11:00
parent 06f75859fa
commit 7b842d2c1c
3 changed files with 14 additions and 4 deletions

View File

@ -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 {

View File

@ -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) {

View File

@ -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()));