Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f84b7d5

Browse files
committed
MSC2545StickerPicker: comply to optional datatypes
1 parent dbea205 commit f84b7d5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/components/views/rooms/MSC2545StickerPicker.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ const PACK_ROOM_EVENT_TYPE = "im.ponies.room_emotes";
3636
const cc = (thing: string) => "mx_2545Stickers_" + thing;
3737

3838
interface I2545Image {
39-
body: string;
40-
info: IImageInfo;
4139
url: string; // mxc
42-
usage: ("sticker" | "emoticon")[];
40+
body?: string;
41+
info?: IImageInfo;
42+
// 2545: If present and non-empty, this overrides the usage defined at pack level for this particular image
43+
usage?: ("sticker" | "emoticon")[];
4344
}
4445

4546
interface I2545Pack {
4647
pack: {
47-
attribution: string;
48-
avatar_url: string;
49-
display_name: string;
48+
attribution?: string;
49+
// 2545: If the usage is absent or empty, a usage for all possible usage types is to be assumed.
50+
usage?: ("emoticon" | "sticker")[];
51+
avatar_url?: string;
52+
display_name?: string;
5053
};
5154
images: {
5255
[id: string]: I2545Image;
@@ -121,12 +124,13 @@ export const MSC2545StickerPicker: React.FC<{
121124
const renderedPacks = packs.map(({ pack, packName }, packIdx) => {
122125
const lcFilter = searchFilter.toLowerCase().trim(); // filter is case insensitive
123126
const images = Object.values(pack.images)
124-
.filter(im => im.body.toLowerCase().includes(lcFilter));
127+
.filter(im => (im.body || "").toLowerCase().includes(lcFilter));
125128

126129
if (images.length == 0) return;
127130

131+
const progressiveDisplayName = pack.pack.display_name || packName;
128132
return <div key={"pack-" + packName}>
129-
<h3 className={cc("label")}>{pack.pack.display_name}</h3>
133+
<h3 className={cc("label")}>{progressiveDisplayName}</h3>
130134
<div className={cc("grid")}>
131135
{images.map((im, idx) => <PackImage
132136
innerRef={(!packIdx && !idx) ? topStickerRef : null}

0 commit comments

Comments
 (0)