Skip to content

Commit d1f283d

Browse files
committed
Show image attachments on the web interface
1 parent c933439 commit d1f283d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Version 0.2.0
66

77
To be released.
88

9+
- Image attachments in posts became shown in the web interface.
10+
911

1012
Version 0.1.1
1113
-------------

src/components/Message.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/** @jsx react-jsx */
1717
/** @jsxImportSource @hono/hono/jsx */
1818
import { LanguageString } from "@fedify/fedify/runtime";
19-
import { getActorHandle, Link } from "@fedify/fedify/vocab";
19+
import { Document, getActorHandle, Image, Link } from "@fedify/fedify/vocab";
2020
import type { MessageClass } from "../message.ts";
2121
import type { Session } from "../session.ts";
2222

@@ -40,6 +40,7 @@ export async function Message({ session, message }: MessageProps) {
4040
suppressError: true,
4141
});
4242
const authorHandle = author == null ? null : await getActorHandle(author);
43+
const attachments = await Array.fromAsync(message.getAttachments());
4344
return (
4445
<article>
4546
<header>
@@ -75,6 +76,25 @@ export async function Message({ session, message }: MessageProps) {
7576
? message.content.language.compact()
7677
: undefined}
7778
/>
79+
{attachments.length > 0 && (
80+
<div>
81+
{attachments.filter((a) =>
82+
a instanceof Image || a instanceof Document
83+
).filter((a) => a.mediaType?.startsWith("image/") && a.url != null)
84+
.map((a) => (
85+
<figure>
86+
<img
87+
src={a.url instanceof Link ? a.url.href?.href : a.url!.href}
88+
width={a.width ?? undefined}
89+
height={a.height ?? undefined}
90+
alt={a.name?.toString() ?? undefined}
91+
style="max-width: 75%;"
92+
/>
93+
<figcaption>{a.name?.toString()}</figcaption>
94+
</figure>
95+
))}
96+
</div>
97+
)}
7898
<footer>
7999
{message.published &&
80100
(

0 commit comments

Comments
 (0)