Co-authored-by: scott@signal.org
Co-authored-by: ken@signal.org
This commit is contained in:
Ken Powers 2019-05-16 15:32:11 -07:00 committed by Scott Nonnenberg
parent 8c8856785b
commit 29de50c12a
100 changed files with 7572 additions and 693 deletions

View file

@ -1110,6 +1110,11 @@ MessageReceiver.prototype.extend({
return this.handleVerified(envelope, syncMessage.verified);
} else if (syncMessage.configuration) {
return this.handleConfiguration(envelope, syncMessage.configuration);
} else if (syncMessage.stickerPackOperation) {
return this.handleStickerPackOperation(
envelope,
syncMessage.stickerPackOperation
);
}
throw new Error('Got empty SyncMessage');
},
@ -1120,6 +1125,19 @@ MessageReceiver.prototype.extend({
ev.configuration = configuration;
return this.dispatchAndWait(ev);
},
handleStickerPackOperation(envelope, operations) {
const ENUM = textsecure.protobuf.SyncMessage.StickerPackOperation.Type;
window.log.info('got sticker pack operation sync message');
const ev = new Event('sticker-pack');
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.stickerPacks = operations.map(operation => ({
id: operation.packId ? operation.packId.toString('hex') : null,
key: operation.packKey ? operation.packKey.toString('base64') : null,
isInstall: operation.type === ENUM.INSTALL,
isRemove: operation.type === ENUM.REMOVE,
}));
return this.dispatchAndWait(ev);
},
handleVerified(envelope, verified) {
const ev = new Event('verified');
ev.confirm = this.removeFromCache.bind(this, envelope);
@ -1231,6 +1249,10 @@ MessageReceiver.prototype.extend({
const encrypted = await this.server.getAttachment(attachment.id);
const { key, digest, size } = attachment;
if (!digest) {
throw new Error('Failure: Ask sender to update Signal and resend.');
}
const data = await textsecure.crypto.decryptAttachment(
encrypted,
window.Signal.Crypto.base64ToArrayBuffer(key),
@ -1400,6 +1422,19 @@ MessageReceiver.prototype.extend({
);
}
const { sticker } = decrypted;
if (sticker) {
if (sticker.packId) {
sticker.packId = sticker.packId.toString('hex');
}
if (sticker.packKey) {
sticker.packKey = sticker.packKey.toString('base64');
}
if (sticker.data) {
sticker.data = this.cleanAttachment(sticker.data);
}
}
return Promise.all(promises).then(() => decrypted);
/* eslint-enable no-bitwise, no-param-reassign */
},