use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId in project Signal-Android by WhisperSystems.
the class AttachmentDownloadJob method createAttachmentPointer.
private SignalServiceAttachmentPointer createAttachmentPointer(Attachment attachment) throws InvalidPartException {
if (TextUtils.isEmpty(attachment.getLocation())) {
throw new InvalidPartException("empty content id");
}
if (TextUtils.isEmpty(attachment.getKey())) {
throw new InvalidPartException("empty encrypted key");
}
try {
final SignalServiceAttachmentRemoteId remoteId = SignalServiceAttachmentRemoteId.from(attachment.getLocation());
final byte[] key = Base64.decode(attachment.getKey());
if (attachment.getDigest() != null) {
Log.i(TAG, "Downloading attachment with digest: " + Hex.toString(attachment.getDigest()));
} else {
Log.i(TAG, "Downloading attachment with no digest...");
}
return new SignalServiceAttachmentPointer(attachment.getCdnNumber(), remoteId, null, key, Optional.of(Util.toIntExact(attachment.getSize())), Optional.absent(), 0, 0, Optional.fromNullable(attachment.getDigest()), Optional.fromNullable(attachment.getFileName()), attachment.isVoiceNote(), attachment.isBorderless(), attachment.isVideoGif(), Optional.absent(), Optional.fromNullable(attachment.getBlurHash()).transform(BlurHash::getHash), attachment.getUploadTimestamp());
} catch (IOException | ArithmeticException e) {
Log.w(TAG, e);
throw new InvalidPartException(e);
}
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId in project Signal-Android by WhisperSystems.
the class SignalServiceMessageSender method uploadAttachmentV2.
private SignalServiceAttachmentPointer uploadAttachmentV2(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
AttachmentV2UploadAttributes v2UploadAttributes = null;
Log.d(TAG, "Using pipe to retrieve attachment upload attributes...");
try {
v2UploadAttributes = new AttachmentService.AttachmentAttributesResponseProcessor<>(attachmentService.getAttachmentV2UploadAttributes().blockingGet()).getResultOrThrow();
} catch (WebSocketUnavailableException e) {
Log.w(TAG, "[uploadAttachmentV2] Pipe unavailable, falling back... (" + e.getClass().getSimpleName() + ": " + e.getMessage() + ")");
} catch (IOException e) {
Log.w(TAG, "Failed to retrieve attachment upload attributes using pipe. Falling back...");
}
if (v2UploadAttributes == null) {
Log.d(TAG, "Not using pipe to retrieve attachment upload attributes...");
v2UploadAttributes = socket.getAttachmentV2UploadAttributes();
}
Pair<Long, byte[]> attachmentIdAndDigest = socket.uploadAttachment(attachmentData, v2UploadAttributes);
return new SignalServiceAttachmentPointer(0, new SignalServiceAttachmentRemoteId(attachmentIdAndDigest.first()), attachment.getContentType(), attachmentKey, Optional.of(Util.toIntExact(attachment.getLength())), attachment.getPreview(), attachment.getWidth(), attachment.getHeight(), Optional.of(attachmentIdAndDigest.second()), attachment.getFileName(), attachment.getVoiceNote(), attachment.isBorderless(), attachment.isGif(), attachment.getCaption(), attachment.getBlurHash(), attachment.getUploadTimestamp());
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId in project Signal-Android by signalapp.
the class AvatarGroupsV1DownloadJob method onRun.
@Override
public void onRun() throws IOException {
GroupDatabase database = SignalDatabase.groups();
Optional<GroupRecord> record = database.getGroup(groupId);
File attachment = null;
try {
if (record.isPresent()) {
long avatarId = record.get().getAvatarId();
String contentType = record.get().getAvatarContentType();
byte[] key = record.get().getAvatarKey();
String relay = record.get().getRelay();
Optional<byte[]> digest = Optional.fromNullable(record.get().getAvatarDigest());
Optional<String> fileName = Optional.absent();
if (avatarId == -1 || key == null) {
return;
}
if (digest.isPresent()) {
Log.i(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
}
attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
attachment.deleteOnExit();
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(0, new SignalServiceAttachmentRemoteId(avatarId), contentType, key, Optional.of(0), Optional.absent(), 0, 0, digest, fileName, false, false, false, Optional.absent(), Optional.absent(), System.currentTimeMillis());
InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, AvatarHelper.AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE);
AvatarHelper.setAvatar(context, record.get().getRecipientId(), inputStream);
SignalDatabase.groups().onAvatarUpdated(groupId, true);
inputStream.close();
}
} catch (NonSuccessfulResponseCodeException | InvalidMessageException | MissingConfigurationException e) {
Log.w(TAG, e);
} finally {
if (attachment != null)
attachment.delete();
}
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId in project Signal-Android by signalapp.
the class SignalServiceMessageSender method uploadAttachmentV2.
private SignalServiceAttachmentPointer uploadAttachmentV2(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
AttachmentV2UploadAttributes v2UploadAttributes = null;
Log.d(TAG, "Using pipe to retrieve attachment upload attributes...");
try {
v2UploadAttributes = new AttachmentService.AttachmentAttributesResponseProcessor<>(attachmentService.getAttachmentV2UploadAttributes().blockingGet()).getResultOrThrow();
} catch (WebSocketUnavailableException e) {
Log.w(TAG, "[uploadAttachmentV2] Pipe unavailable, falling back... (" + e.getClass().getSimpleName() + ": " + e.getMessage() + ")");
} catch (IOException e) {
Log.w(TAG, "Failed to retrieve attachment upload attributes using pipe. Falling back...");
}
if (v2UploadAttributes == null) {
Log.d(TAG, "Not using pipe to retrieve attachment upload attributes...");
v2UploadAttributes = socket.getAttachmentV2UploadAttributes();
}
Pair<Long, byte[]> attachmentIdAndDigest = socket.uploadAttachment(attachmentData, v2UploadAttributes);
return new SignalServiceAttachmentPointer(0, new SignalServiceAttachmentRemoteId(attachmentIdAndDigest.first()), attachment.getContentType(), attachmentKey, Optional.of(Util.toIntExact(attachment.getLength())), attachment.getPreview(), attachment.getWidth(), attachment.getHeight(), Optional.of(attachmentIdAndDigest.second()), attachment.getFileName(), attachment.getVoiceNote(), attachment.isBorderless(), attachment.isGif(), attachment.getCaption(), attachment.getBlurHash(), attachment.getUploadTimestamp());
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId in project Signal-Android by WhisperSystems.
the class PushSendJob method getAttachmentPointerFor.
@Nullable
protected SignalServiceAttachment getAttachmentPointerFor(Attachment attachment) {
if (TextUtils.isEmpty(attachment.getLocation())) {
Log.w(TAG, "empty content id");
return null;
}
if (TextUtils.isEmpty(attachment.getKey())) {
Log.w(TAG, "empty encrypted key");
return null;
}
try {
final SignalServiceAttachmentRemoteId remoteId = SignalServiceAttachmentRemoteId.from(attachment.getLocation());
final byte[] key = Base64.decode(attachment.getKey());
int width = attachment.getWidth();
int height = attachment.getHeight();
if ((width == 0 || height == 0) && MediaUtil.hasVideoThumbnail(context, attachment.getUri())) {
Bitmap thumbnail = MediaUtil.getVideoThumbnail(context, attachment.getUri(), 1000);
if (thumbnail != null) {
width = thumbnail.getWidth();
height = thumbnail.getHeight();
}
}
return new SignalServiceAttachmentPointer(attachment.getCdnNumber(), remoteId, attachment.getContentType(), key, Optional.of(Util.toIntExact(attachment.getSize())), Optional.absent(), width, height, Optional.fromNullable(attachment.getDigest()), Optional.fromNullable(attachment.getFileName()), attachment.isVoiceNote(), attachment.isBorderless(), attachment.isVideoGif(), Optional.fromNullable(attachment.getCaption()), Optional.fromNullable(attachment.getBlurHash()).transform(BlurHash::getHash), attachment.getUploadTimestamp());
} catch (IOException | ArithmeticException e) {
Log.w(TAG, e);
return null;
}
}
Aggregations