diff --git a/src/app/features/room/MediaGallery.tsx b/src/app/features/room/MediaGallery.tsx index fd5350518..c11eea64e 100644 --- a/src/app/features/room/MediaGallery.tsx +++ b/src/app/features/room/MediaGallery.tsx @@ -106,6 +106,10 @@ export type LightboxItem = { mimeType?: string; msgtype: MsgType.Image | MsgType.Video; body: string; + /** The file's name when the message also carries a caption (MSC2530). */ + filename?: string; + /** Caption text: `body` when it differs from `filename`. */ + caption?: string; sender: string; ts: number; eventId: string; @@ -127,12 +131,19 @@ export function toLightboxItems(room: Room, events: MatrixEvent[]): LightboxItem .map((ev) => { const c = ev.getContent(); const isEnc = !!c.file; + const filename = typeof c.filename === 'string' && c.filename ? c.filename : undefined; + const caption = + filename && typeof c.body === 'string' && c.body && c.body !== filename + ? c.body + : undefined; return { mxcUrl: c.file?.url ?? c.url ?? '', encInfo: isEnc ? c.file : undefined, mimeType: c.info?.mimetype, msgtype: c.msgtype as MsgType.Image | MsgType.Video, body: c.body ?? '', + filename, + caption, sender: getSenderName(room, ev.getSender() ?? ''), ts: ev.getTs(), eventId: ev.getId() ?? '', @@ -209,7 +220,7 @@ function LightboxMedia({ ) : ( {item.body} - {item.body || (item.msgtype === MsgType.Video ? 'Video' : 'Image')} + {item.filename || item.body || (item.msgtype === MsgType.Video ? 'Video' : 'Image')} {item.sender} · {dateStr} @@ -412,7 +423,7 @@ export function Lightbox({ {(ref) => ( )} + {item.caption && ( + // [Gitea #164] The full caption, readable — the header only has room + // for one truncated line. + + + {item.caption} + + + )}