mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-23 18:49:37 +00:00
Support for attachment digests
// FREEBIE
This commit is contained in:
@@ -19,9 +19,11 @@ import org.thoughtcrime.securesms.events.PartProgressEvent;
|
||||
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
||||
import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirement;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
@@ -149,7 +151,13 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
|
||||
relay = attachment.getRelay();
|
||||
}
|
||||
|
||||
return new SignalServiceAttachmentPointer(id, null, key, relay);
|
||||
if (attachment.getDigest() != null) {
|
||||
Log.w(TAG, "Downloading attachment with digest: " + Hex.toString(attachment.getDigest()));
|
||||
} else {
|
||||
Log.w(TAG, "Downloading attachment with no digest...");
|
||||
}
|
||||
|
||||
return new SignalServiceAttachmentPointer(id, null, key, relay, Optional.fromNullable(attachment.getDigest()));
|
||||
} catch (InvalidMessageException | IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new InvalidPartException(e);
|
||||
|
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.jobs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
@@ -12,9 +13,11 @@ import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel;
|
||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
@@ -35,7 +38,7 @@ public class AvatarDownloadJob extends MasterSecretJob implements InjectableType
|
||||
|
||||
private final byte[] groupId;
|
||||
|
||||
public AvatarDownloadJob(Context context, byte[] groupId) {
|
||||
public AvatarDownloadJob(Context context, @NonNull byte[] groupId) {
|
||||
super(context, JobParameters.newBuilder()
|
||||
.withRequirement(new MasterSecretRequirement(context))
|
||||
.withRequirement(new NetworkRequirement(context))
|
||||
@@ -56,21 +59,24 @@ public class AvatarDownloadJob extends MasterSecretJob implements InjectableType
|
||||
|
||||
try {
|
||||
if (record != null) {
|
||||
long avatarId = record.getAvatarId();
|
||||
String contentType = record.getAvatarContentType();
|
||||
byte[] key = record.getAvatarKey();
|
||||
String relay = record.getRelay();
|
||||
long avatarId = record.getAvatarId();
|
||||
String contentType = record.getAvatarContentType();
|
||||
byte[] key = record.getAvatarKey();
|
||||
String relay = record.getRelay();
|
||||
Optional<byte[]> digest = Optional.fromNullable(record.getAvatarDigest());
|
||||
|
||||
if (avatarId == -1 || key == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (digest.isPresent()) {
|
||||
Log.w(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
|
||||
}
|
||||
|
||||
attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
|
||||
attachment.deleteOnExit();
|
||||
|
||||
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay);
|
||||
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay, digest);
|
||||
InputStream inputStream = receiver.retrieveAttachment(pointer, attachment);
|
||||
Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key), 500, 500);
|
||||
|
||||
|
Reference in New Issue
Block a user