Skip to content

Commit

Permalink
A few fixes for the emoji bundled with stickers
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Aug 8, 2022
1 parent 7a1686b commit fde917c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
13 changes: 10 additions & 3 deletions sticker-creator/window/phase3-sticker-functions.ts
Expand Up @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions ts/models/messages.ts
Expand Up @@ -731,11 +731,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {

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');
}
Expand Down
2 changes: 2 additions & 0 deletions ts/test-both/processDataMessage_test.ts
Expand Up @@ -299,6 +299,7 @@ describe('processDataMessage', () => {
packId: new Uint8Array([1, 2, 3]),
packKey: new Uint8Array([4, 5, 6]),
stickerId: 1,
emoji: '💯',
data: UNPROCESSED_ATTACHMENT,
},
});
Expand All @@ -307,6 +308,7 @@ describe('processDataMessage', () => {
packId: '010203',
packKey: 'BAUG',
stickerId: 1,
emoji: '💯',
data: PROCESSED_ATTACHMENT,
});
});
Expand Down
1 change: 1 addition & 0 deletions ts/textsecure/Types.d.ts
Expand Up @@ -171,6 +171,7 @@ export type ProcessedSticker = {
packId?: string;
packKey?: string;
stickerId?: number;
emoji?: string;
data?: ProcessedAttachment;
};

Expand Down
1 change: 1 addition & 0 deletions ts/textsecure/processDataMessage.ts
Expand Up @@ -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),
};
}
Expand Down
12 changes: 12 additions & 0 deletions ts/types/Stickers.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit fde917c

Please sign in to comment.