Skip to content

Commit

Permalink
Support rendering image reactions for mxc keys
Browse files Browse the repository at this point in the history
Beeper clients only use an mxc url as reaction key when sending image
reactions, instead of properly setting the url field.
  • Loading branch information
SpiritCroc committed Jun 8, 2023
1 parent f064216 commit 4d104fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/customisations/models/IMediaEventContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export function prepEventContentAsMedia(content: Partial<IMediaEventContent>): I
mxc: content.file.url,
file: content.file,
};
} else if (content["m.relates_to"]?.key?.startsWith("mxc://")) {
// Fallback to key, since some clients only set the key to the mxc:// url while omitting the actual url field for reactions
return {
thumbnail,
mxc: content["m.relates_to"]?.key,
file: content.file,
};
}

throw new Error("Invalid file provided: cannot determine MXC URI. Has it been redacted?");
Expand Down
4 changes: 4 additions & 0 deletions src/utils/MediaEventHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export class MediaEventHelper implements IDestroyable {
const mediaMsgTypes: string[] = [MsgType.Video, MsgType.Audio, MsgType.Image, MsgType.File];
if (mediaMsgTypes.includes(content.msgtype!)) return true;
if (typeof content.url === "string") return true;
if (event.getType() === EventType.Reaction && content["m.relates_to"]?.key?.startsWith("mxc://")) {
// Some clients only send mxc url as key, without setting the url field
return true;
}

// Finally, it's probably not media
return false;
Expand Down

0 comments on commit 4d104fc

Please sign in to comment.