Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/botkit/src/components/Follower.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// BotKit by Fedify: A framework for creating ActivityPub bots
// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @jsx react-jsx */
/** @jsxImportSource hono/jsx */
import { type Actor, getActorHandle, Link } from "@fedify/fedify/vocab";
import type { Session } from "../session.ts";

export interface FollowerProps {
readonly actor: Actor;
readonly session: Session<unknown>;
}

export async function Follower({ actor, session }: FollowerProps) {
const { context } = session;
const author = actor;
const authorIcon = await actor?.getIcon({
documentLoader: context.documentLoader,
contextLoader: context.contextLoader,
suppressError: true,
});
const authorHandle = await getActorHandle(author);

return (
<article>
<header>
{author?.id
? (
<hgroup>
{authorIcon?.url && (
<img
src={authorIcon.url instanceof Link
? authorIcon.url.href?.href
: authorIcon.url.href}
width={authorIcon.width ?? undefined}
height={authorIcon.height ?? undefined}
alt={authorIcon.name?.toString() ?? undefined}
style="float: left; margin-right: 1em; height: 64px;"
/>
)}
<h3>
<a href={author.url?.href?.toString() ?? author.id.href}>
{author.name}
</a>
</h3>{" "}
<p>
<span style="user-select: all;">{authorHandle}</span>
</p>
</hgroup>
)
: <em>(Deleted account)</em>}
</header>
</article>
);
}
48 changes: 45 additions & 3 deletions packages/botkit/src/pages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { decode } from "html-entities";
import type { BotImpl } from "./bot-impl.ts";
import { Layout } from "./components/Layout.tsx";
import { Message } from "./components/Message.tsx";
import { Follower } from "./components/Follower.tsx";
import { getMessageClass, isMessageObject, textXss } from "./message-impl.ts";
import type { MessageClass } from "./message.ts";
import type { Uuid } from "./repository.ts";
Expand Down Expand Up @@ -142,9 +143,11 @@ app.get("/", async (c) => {
</a>{" "}
&middot;{" "}
<span>
{followersCount === 1
? `1 follower`
: `${followersCount.toLocaleString("en")} followers`}
<a href="/followers">
{followersCount === 1
? `1 follower`
: `${followersCount.toLocaleString("en")} followers`}
</a>
</span>{" "}
&middot;{" "}
<span>
Expand Down Expand Up @@ -206,6 +209,45 @@ app.get("/", async (c) => {
);
});

app.get("/followers", async (c) => {
const { bot } = c.env;
const ctx = bot.federation.createContext(c.req.raw, c.env.contextData);
const session = bot.getSession(ctx);
const followersCount = await bot.repository.countFollowers();
const followers = await Array.fromAsync(bot.repository.getFollowers());

const url = new URL(c.req.url);
const activityLink = ctx.getActorUri(bot.identifier);
const feedLink = new URL("/feed.xml", url);

return c.html(
<Layout
bot={bot}
host={url.host}
activityLink={activityLink}
feedLink={feedLink}
>
<header class="container">
<h1>
<a href="/">&larr;</a>{" "}
{followersCount === 1
? `1 follower`
: `${followersCount.toLocaleString("en")} followers`}
</h1>
</header>
<main class="container">
{followers.map((follower, index) => (
<Follower
key={follower.id?.href ?? index}
actor={follower}
session={session}
/>
))}
</main>
</Layout>,
);
});

app.get("/tags/:hashtag", async (c) => {
const hashtag = c.req.param("hashtag");
const { bot } = c.env;
Expand Down
Loading