Update proto id and use the server id as the attachmentpointer id

pull/561/head
Beaudan Brown 6 years ago
parent 5710c1268c
commit c7a91686a8

@ -51,7 +51,11 @@ class LokiFileServerAPI {
} }
const url = response.data && response.data.url; const url = response.data && response.data.url;
return url; const id = response.data && response.data.id;
return {
url,
id,
};
} }
} }

@ -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 */ /* eslint-disable more/no-then, no-bitwise */
@ -191,38 +191,35 @@ MessageSender.prototype = {
return textsecure.crypto return textsecure.crypto
.encryptAttachment(attachment.data, proto.key, iv) .encryptAttachment(attachment.data, proto.key, iv)
.then(result => .then(result =>
this.server.putAttachment(result.ciphertext).then(async url => { this.server
const urlBuffer = dcodeIO.ByteBuffer.wrap( .putAttachment(result.ciphertext)
url, .then(async ({ url, id }) => {
'utf8' proto.id = id;
).toArrayBuffer(); proto.url = url;
const idBuffer = await libloki.crypto.sha512(urlBuffer); proto.contentType = attachment.contentType;
proto.id = dcodeIO.ByteBuffer.wrap(idBuffer).toString('base64'); proto.digest = result.digest;
proto.url = url;
proto.contentType = attachment.contentType; if (attachment.size) {
proto.digest = result.digest; proto.size = attachment.size;
}
if (attachment.size) { if (attachment.fileName) {
proto.size = attachment.size; proto.fileName = attachment.fileName;
} }
if (attachment.fileName) { if (attachment.flags) {
proto.fileName = attachment.fileName; proto.flags = attachment.flags;
} }
if (attachment.flags) { if (attachment.width) {
proto.flags = attachment.flags; proto.width = attachment.width;
} }
if (attachment.width) { if (attachment.height) {
proto.width = attachment.width; proto.height = attachment.height;
} }
if (attachment.height) { if (attachment.caption) {
proto.height = attachment.height; proto.caption = attachment.caption;
} }
if (attachment.caption) {
proto.caption = attachment.caption; return proto;
} })
return proto;
})
); );
}, },

@ -320,7 +320,7 @@ message AttachmentPointer {
optional uint32 width = 9; optional uint32 width = 9;
optional uint32 height = 10; optional uint32 height = 10;
optional string caption = 11; optional string caption = 11;
optional string url = 12; optional string url = 101;
} }
message GroupContext { message GroupContext {

Loading…
Cancel
Save