Skip to content

Commit f98eca6

Browse files
committed
Don't fetch the bot actor
1 parent 1a749b5 commit f98eca6

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/components/Message.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
/** @jsx react-jsx */
1717
/** @jsxImportSource @hono/hono/jsx */
18-
import type { Context } from "@fedify/fedify/federation";
1918
import { LanguageString } from "@fedify/fedify/runtime";
2019
import { getActorHandle, Link } from "@fedify/fedify/vocab";
2120
import type { MessageClass } from "../message.ts";
21+
import type { Session } from "../session.ts";
2222

2323
export interface MessageProps {
2424
readonly message: MessageClass;
25-
readonly context: Context<unknown>;
25+
readonly session: Session<unknown>;
2626
}
2727

28-
export async function Message({ context, message }: MessageProps) {
29-
const author = await message.getAttribution({
30-
documentLoader: context.documentLoader,
31-
contextLoader: context.contextLoader,
32-
suppressError: true,
33-
});
28+
export async function Message({ session, message }: MessageProps) {
29+
const { context } = session;
30+
const author = message.attributionId?.href === session.actorId?.href
31+
? await session.getActor()
32+
: await message.getAttribution({
33+
documentLoader: context.documentLoader,
34+
contextLoader: context.contextLoader,
35+
suppressError: true,
36+
});
3437
const authorIcon = await author?.getIcon({
3538
documentLoader: context.documentLoader,
3639
contextLoader: context.contextLoader,

src/pages.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ app.get("/", async (c) => {
169169
)}
170170
</header>
171171
<main class="container">
172-
{messages.map((message) => <Message message={message} context={ctx} />)}
172+
{messages.map((message) => (
173+
<Message message={message} session={session} />
174+
))}
173175
</main>
174176
<footer class="container">
175177
<nav style="display: block; text-align: end;">
@@ -200,6 +202,7 @@ app.get("/message/:id", async (c) => {
200202
const { bot } = c.env;
201203
const url = new URL(c.req.url);
202204
const ctx = bot.federation.createContext(c.req.raw, c.env.contextData);
205+
const session = bot.getSession(ctx);
203206
const post = await bot.repository.getMessage(id as Uuid);
204207
if (post == null || !isPublic(post)) return c.notFound();
205208
const message = await post.getObject(ctx);
@@ -211,7 +214,7 @@ app.get("/message/:id", async (c) => {
211214
return c.html(
212215
<Layout bot={bot} host={url.host} activityLink={activityLink}>
213216
<main class="container">
214-
<Message message={message} context={ctx} />
217+
<Message message={message} session={session} />
215218
</main>
216219
</Layout>,
217220
{

0 commit comments

Comments
 (0)