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) { async sendStickerMessage(packId, stickerId) {
if (!window.ENABLE_STICKER_SEND) {
return;
}
const packData = window.Signal.Stickers.getStickerPack(packId); const packData = window.Signal.Stickers.getStickerPack(packId);
const stickerData = window.Signal.Stickers.getSticker(packId, stickerId); const stickerData = window.Signal.Stickers.getSticker(packId, stickerId);
if (!stickerData || !packData) { if (!stickerData || !packData) {

View file

@ -1061,7 +1061,6 @@
quote: quoteWithData, quote: quoteWithData,
preview: previewWithData, preview: previewWithData,
sticker: stickerWithData, sticker: stickerWithData,
needsSync: !this.get('synced'),
expireTimer: this.get('expireTimer'), expireTimer: this.get('expireTimer'),
profileKey, profileKey,
group: { group: {
@ -1165,7 +1164,11 @@
// This is used by sendSyncMessage, then set to null // This is used by sendSyncMessage, then set to null
if (result.dataMessage) { 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') || []; const sentTo = this.get('sent_to') || [];
@ -1301,7 +1304,7 @@
const isUpdate = Boolean(this.get('synced')); const isUpdate = Boolean(this.get('synced'));
// Until isRecipientUpdate sync messages are widely supported, will not send them // Until isRecipientUpdate sync messages are widely supported, will not send them
if (isUpdate) { if (isUpdate && !window.SEND_RECIPIENT_UPDATES) {
return Promise.resolve(); return Promise.resolve();
} }

View file

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

View file

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

View file

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

View file

@ -1,5 +1,4 @@
/* global Whisper: false */ /* global Whisper, window */
/* global window: false */
const electron = require('electron'); const electron = require('electron');
const semver = require('semver'); const semver = require('semver');
@ -9,6 +8,12 @@ const { deferredToPromise } = require('./js/modules/deferred_to_promise');
const { app } = electron.remote; const { app } = electron.remote;
const { systemPreferences } = electron.remote.require('electron'); 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'; window.PROTO_ROOT = 'protos';
const config = require('url').parse(window.location.toString(), true).query; const config = require('url').parse(window.location.toString(), true).query;