From c7a91686a8877452135681e6d4f98b4b0f2455ef Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Thu, 17 Oct 2019 16:49:44 +1100 Subject: [PATCH] Update proto id and use the server id as the attachmentpointer id --- js/modules/loki_file_server_api.js | 6 ++- libtextsecure/sendmessage.js | 63 ++++++++++++++---------------- protos/SignalService.proto | 2 +- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/js/modules/loki_file_server_api.js b/js/modules/loki_file_server_api.js index de25a4292..61caaffd3 100644 --- a/js/modules/loki_file_server_api.js +++ b/js/modules/loki_file_server_api.js @@ -51,7 +51,11 @@ class LokiFileServerAPI { } const url = response.data && response.data.url; - return url; + const id = response.data && response.data.id; + return { + url, + id, + }; } } diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index d00468f80..bdc2fe2c2 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -1,4 +1,4 @@ -/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window, dcodeIO, libloki */ +/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window */ /* eslint-disable more/no-then, no-bitwise */ @@ -191,38 +191,35 @@ MessageSender.prototype = { return textsecure.crypto .encryptAttachment(attachment.data, proto.key, iv) .then(result => - this.server.putAttachment(result.ciphertext).then(async url => { - const urlBuffer = dcodeIO.ByteBuffer.wrap( - url, - 'utf8' - ).toArrayBuffer(); - const idBuffer = await libloki.crypto.sha512(urlBuffer); - proto.id = dcodeIO.ByteBuffer.wrap(idBuffer).toString('base64'); - proto.url = url; - proto.contentType = attachment.contentType; - proto.digest = result.digest; - - if (attachment.size) { - proto.size = attachment.size; - } - if (attachment.fileName) { - proto.fileName = attachment.fileName; - } - if (attachment.flags) { - proto.flags = attachment.flags; - } - if (attachment.width) { - proto.width = attachment.width; - } - if (attachment.height) { - proto.height = attachment.height; - } - if (attachment.caption) { - proto.caption = attachment.caption; - } - - return proto; - }) + this.server + .putAttachment(result.ciphertext) + .then(async ({ url, id }) => { + proto.id = id; + proto.url = url; + proto.contentType = attachment.contentType; + proto.digest = result.digest; + + if (attachment.size) { + proto.size = attachment.size; + } + if (attachment.fileName) { + proto.fileName = attachment.fileName; + } + if (attachment.flags) { + proto.flags = attachment.flags; + } + if (attachment.width) { + proto.width = attachment.width; + } + if (attachment.height) { + proto.height = attachment.height; + } + if (attachment.caption) { + proto.caption = attachment.caption; + } + + return proto; + }) ); }, diff --git a/protos/SignalService.proto b/protos/SignalService.proto index e5542947a..f9495b919 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -320,7 +320,7 @@ message AttachmentPointer { optional uint32 width = 9; optional uint32 height = 10; optional string caption = 11; - optional string url = 12; + optional string url = 101; } message GroupContext {