From fd06ac9d57062e27b34012d3c26feda58d54b843 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Mon, 31 Aug 2020 11:29:22 -0500 Subject: [PATCH] Sticker improvements --- js/modules/stickers.js | 5 +---- main.js | 4 +++- ts/textsecure/WebAPI.ts | 8 +++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/js/modules/stickers.js b/js/modules/stickers.js index b5f55985ba6a..94c914080eb1 100644 --- a/js/modules/stickers.js +++ b/js/modules/stickers.js @@ -666,10 +666,7 @@ function getStickerPackStatus(packId) { } function getSticker(packId, stickerId) { - const state = reduxStore.getState(); - const { stickers } = state; - const { packs } = stickers; - const pack = packs[packId]; + const pack = getStickerPack(packId); if (!pack || !pack.stickers) { return null; diff --git a/main.js b/main.js index 1d03473fbf10..76ee427e6224 100644 --- a/main.js +++ b/main.js @@ -1384,7 +1384,9 @@ function handleSgnlHref(incomingHref) { console.log('Opening sticker pack from sgnl protocol link'); const packId = args.get('pack_id'); const packKeyHex = args.get('pack_key'); - const packKey = Buffer.from(packKeyHex, 'hex').toString('base64'); + const packKey = packKeyHex + ? Buffer.from(packKeyHex, 'hex').toString('base64') + : ''; mainWindow.webContents.send('show-sticker-pack', { packId, packKey }); } else { console.error('Unhandled sgnl link'); diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index e12f2309108b..d67d1eff4c54 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -5,7 +5,7 @@ import { Agent } from 'https'; import { escapeRegExp } from 'lodash'; import is from '@sindresorhus/is'; -import { redactPackId } from '../../js/modules/stickers'; +import { isPackIdValid, redactPackId } from '../../js/modules/stickers'; import { getRandomValue } from '../Crypto'; import MessageSender from './SendMessage'; @@ -1344,6 +1344,9 @@ export function initialize({ } async function getSticker(packId: string, stickerId: string) { + if (!isPackIdValid(packId)) { + throw new Error('getSticker: pack ID was invalid'); + } return _outerAjax( `${cdnUrlObject['0']}/stickers/${packId}/full/${stickerId}`, { @@ -1358,6 +1361,9 @@ export function initialize({ } async function getStickerPackManifest(packId: string) { + if (!isPackIdValid(packId)) { + throw new Error('getStickerPackManifest: pack ID was invalid'); + } return _outerAjax( `${cdnUrlObject['0']}/stickers/${packId}/manifest.proto`, {