From fde917c9838bb641969979b8cb0d91b94543c17f Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 8 Aug 2022 11:21:00 -0700 Subject: [PATCH] A few fixes for the emoji bundled with stickers --- sticker-creator/window/phase3-sticker-functions.ts | 13 ++++++++++--- ts/models/messages.ts | 9 ++++----- ts/test-both/processDataMessage_test.ts | 2 ++ ts/textsecure/Types.d.ts | 1 + ts/textsecure/processDataMessage.ts | 1 + ts/types/Stickers.ts | 12 ++++++++++++ 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/sticker-creator/window/phase3-sticker-functions.ts b/sticker-creator/window/phase3-sticker-functions.ts index 6d9a7415809a..53fceea65409 100644 --- a/sticker-creator/window/phase3-sticker-functions.ts +++ b/sticker-creator/window/phase3-sticker-functions.ts @@ -184,10 +184,17 @@ window.encryptAndUpload = async ( return s; }); - const coverSticker = new Proto.StickerPack.Sticker(); - coverSticker.id = + + const coverStickerId = uniqueStickers.length === stickers.length ? 0 : uniqueStickers.length - 1; - coverSticker.emoji = ''; + const coverStickerData = stickers[coverStickerId]; + const coverSticker = new Proto.StickerPack.Sticker(); + coverSticker.id = coverStickerId; + if (coverStickerData.emoji) { + coverSticker.emoji = coverStickerData.emoji; + } else { + coverSticker.emoji = ''; + } manifestProto.cover = coverSticker; const encryptedManifest = await encrypt( diff --git a/ts/models/messages.ts b/ts/models/messages.ts index f89a5c009a84..874ba531d87d 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -731,11 +731,10 @@ export class MessageModel extends window.Backbone.Model { const stickerData = this.get('sticker'); if (stickerData) { - const sticker = Stickers.getSticker( - stickerData.packId, - stickerData.stickerId - ); - const { emoji } = sticker || {}; + const emoji = + Stickers.getSticker(stickerData.packId, stickerData.stickerId)?.emoji || + stickerData?.emoji; + if (!emoji) { log.warn('Unable to get emoji for sticker'); } diff --git a/ts/test-both/processDataMessage_test.ts b/ts/test-both/processDataMessage_test.ts index bc34c1c22e62..14e1ca1d955b 100644 --- a/ts/test-both/processDataMessage_test.ts +++ b/ts/test-both/processDataMessage_test.ts @@ -299,6 +299,7 @@ describe('processDataMessage', () => { packId: new Uint8Array([1, 2, 3]), packKey: new Uint8Array([4, 5, 6]), stickerId: 1, + emoji: '💯', data: UNPROCESSED_ATTACHMENT, }, }); @@ -307,6 +308,7 @@ describe('processDataMessage', () => { packId: '010203', packKey: 'BAUG', stickerId: 1, + emoji: '💯', data: PROCESSED_ATTACHMENT, }); }); diff --git a/ts/textsecure/Types.d.ts b/ts/textsecure/Types.d.ts index 904af6166b77..fb7e0c4de320 100644 --- a/ts/textsecure/Types.d.ts +++ b/ts/textsecure/Types.d.ts @@ -171,6 +171,7 @@ export type ProcessedSticker = { packId?: string; packKey?: string; stickerId?: number; + emoji?: string; data?: ProcessedAttachment; }; diff --git a/ts/textsecure/processDataMessage.ts b/ts/textsecure/processDataMessage.ts index 7fa08b8eaa4b..226b7b48c4b4 100644 --- a/ts/textsecure/processDataMessage.ts +++ b/ts/textsecure/processDataMessage.ts @@ -212,6 +212,7 @@ export function processSticker( packId: sticker.packId ? Bytes.toHex(sticker.packId) : undefined, packKey: sticker.packKey ? Bytes.toBase64(sticker.packKey) : undefined, stickerId: dropNull(sticker.stickerId), + emoji: dropNull(sticker.emoji), data: processAttachment(sticker.data), }; } diff --git a/ts/types/Stickers.ts b/ts/types/Stickers.ts index d6286a11be1d..092d638b151b 100644 --- a/ts/types/Stickers.ts +++ b/ts/types/Stickers.ts @@ -449,6 +449,12 @@ export async function downloadEphemeralPack( proto.stickers, sticker => !isNumber(sticker.id) || sticker.id === coverStickerId ); + const coverSticker = proto.stickers.filter( + sticker => isNumber(sticker.id) && sticker.id === coverStickerId + ); + if (coverSticker[0] && !coverProto.emoji) { + coverProto.emoji = coverSticker[0].emoji; + } const coverIncludedInList = nonCoverStickers.length < stickerCount; @@ -652,6 +658,12 @@ async function doDownloadStickerPack( proto.stickers, sticker => !isNumber(sticker.id) || sticker.id === coverStickerId ); + const coverSticker = proto.stickers.filter( + sticker => isNumber(sticker.id) && sticker.id === coverStickerId + ); + if (coverSticker[0] && !coverProto.emoji) { + coverProto.emoji = coverSticker[0].emoji; + } coverIncludedInList = nonCoverStickers.length < stickerCount;