Search in sources :

Example 1 with AttachmentV2UploadAttributes

use of org.whispersystems.signalservice.internal.push.AttachmentV2UploadAttributes 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());
}
Also used : AttachmentV2UploadAttributes(org.whispersystems.signalservice.internal.push.AttachmentV2UploadAttributes) SignalServiceAttachmentRemoteId(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) WebSocketUnavailableException(org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 SignalServiceAttachmentPointer (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer)1 SignalServiceAttachmentRemoteId (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId)1 WebSocketUnavailableException (org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException)1 AttachmentV2UploadAttributes (org.whispersystems.signalservice.internal.push.AttachmentV2UploadAttributes)1