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

Commit

Permalink
MSC2545StickerPicker: comply to optional datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
ckiee committed Sep 30, 2022
1 parent dbea205 commit f84b7d5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/components/views/rooms/MSC2545StickerPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ const PACK_ROOM_EVENT_TYPE = "im.ponies.room_emotes";
const cc = (thing: string) => "mx_2545Stickers_" + thing;

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

interface I2545Pack {
pack: {
attribution: string;
avatar_url: string;
display_name: string;
attribution?: string;
// 2545: If the usage is absent or empty, a usage for all possible usage types is to be assumed.
usage?: ("emoticon" | "sticker")[];
avatar_url?: string;
display_name?: string;
};
images: {
[id: string]: I2545Image;
Expand Down Expand Up @@ -121,12 +124,13 @@ export const MSC2545StickerPicker: React.FC<{
const renderedPacks = packs.map(({ pack, packName }, packIdx) => {
const lcFilter = searchFilter.toLowerCase().trim(); // filter is case insensitive
const images = Object.values(pack.images)
.filter(im => im.body.toLowerCase().includes(lcFilter));
.filter(im => (im.body || "").toLowerCase().includes(lcFilter));

if (images.length == 0) return;

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

0 comments on commit f84b7d5

Please sign in to comment.