Refactor 'waiting' flags into one location, fix timestamp check

This commit is contained in:
Scott Nonnenberg 2019-05-16 15:14:06 -07:00
parent fd36720079
commit e18b6bed1f
6 changed files with 39 additions and 13 deletions

View File

@ -866,6 +866,10 @@
},
async sendStickerMessage(packId, stickerId) {
if (!window.ENABLE_STICKER_SEND) {
return;
}
const packData = window.Signal.Stickers.getStickerPack(packId);
const stickerData = window.Signal.Stickers.getSticker(packId, stickerId);
if (!stickerData || !packData) {

View File

@ -1061,7 +1061,6 @@
quote: quoteWithData,
preview: previewWithData,
sticker: stickerWithData,
needsSync: !this.get('synced'),
expireTimer: this.get('expireTimer'),
profileKey,
group: {
@ -1165,7 +1164,11 @@
// This is used by sendSyncMessage, then set to null
if (result.dataMessage) {
this.set({ dataMessage: result.dataMessage });
// When we're not sending recipient updates, we won't save the dataMessage
// unless it's the first time we attempt to send the message.
if (!this.get('synced') || window.SEND_RECIPIENT_UPDATES) {
this.set({ dataMessage: result.dataMessage });
}
}
const sentTo = this.get('sent_to') || [];
@ -1301,7 +1304,7 @@
const isUpdate = Boolean(this.get('synced'));
// Until isRecipientUpdate sync messages are widely supported, will not send them
if (isUpdate) {
if (isUpdate && !window.SEND_RECIPIENT_UPDATES) {
return Promise.resolve();
}

View File

@ -315,6 +315,10 @@
},
setupStickerPickerButton() {
if (!window.ENABLE_STICKER_SEND) {
return;
}
const props = {
onClickAddPack: () => this.showStickerManager(),
onPickSticker: (packId, stickerId) =>
@ -1318,6 +1322,10 @@
},
showStickerPackPreview(packId) {
if (!window.ENABLE_STICKER_SEND) {
return;
}
const props = {
packId,
onClose: () => {

View File

@ -1304,13 +1304,19 @@ MessageReceiver.prototype.extend({
// Note that messages may (generally) only perform one action and we ignore remaining
// fields after the first action.
const TIMESTAMP_VALIDATION = false;
if (TIMESTAMP_VALIDATION && envelope.timestamp !== decrypted.timestamp) {
throw new Error(
`Timestamp ${
decrypted.timestamp
} in DataMessage did not match envelope timestamp ${envelope.timestamp}`
);
if (window.TIMESTAMP_VALIDATION) {
const envelopeTimestamp = envelope.timestamp.toNumber();
const decryptedTimestamp = decrypted.timestamp.toNumber();
if (envelopeTimestamp !== decryptedTimestamp) {
throw new Error(
`Timestamp ${
decrypted.timestamp
} in DataMessage did not match envelope timestamp ${
envelope.timestamp
}`
);
}
}
if (decrypted.flags == null) {

View File

@ -185,7 +185,7 @@ MessageSender.prototype = {
},
getPaddedAttachment(data, shouldPad) {
if (!shouldPad) {
if (!window.PAD_ALL_ATTACHMENTS && !shouldPad) {
return data;
}

View File

@ -1,5 +1,4 @@
/* global Whisper: false */
/* global window: false */
/* global Whisper, window */
const electron = require('electron');
const semver = require('semver');
@ -9,6 +8,12 @@ const { deferredToPromise } = require('./js/modules/deferred_to_promise');
const { app } = electron.remote;
const { systemPreferences } = electron.remote.require('electron');
// Waiting for clients to implement changes on receive side
window.ENABLE_STICKER_SEND = false;
window.TIMESTAMP_VALIDATION = false;
window.PAD_ALL_ATTACHMENTS = false;
window.SEND_RECIPIENT_UPDATES = false;
window.PROTO_ROOT = 'protos';
const config = require('url').parse(window.location.toString(), true).query;