Skip to content

Commit 96958a1

Browse files
committed
Add /followers route
1 parent c6e410a commit 96958a1

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

packages/botkit/src/pages.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { decode } from "html-entities";
3131
import type { BotImpl } from "./bot-impl.ts";
3232
import { Layout } from "./components/Layout.tsx";
3333
import { Message } from "./components/Message.tsx";
34+
import { Follower } from "./components/Follower.tsx";
3435
import { getMessageClass, isMessageObject, textXss } from "./message-impl.ts";
3536
import type { MessageClass } from "./message.ts";
3637
import type { Uuid } from "./repository.ts";
@@ -142,9 +143,11 @@ app.get("/", async (c) => {
142143
</a>{" "}
143144
&middot;{" "}
144145
<span>
145-
{followersCount === 1
146-
? `1 follower`
147-
: `${followersCount.toLocaleString("en")} followers`}
146+
<a href="/followers">
147+
{followersCount === 1
148+
? `1 follower`
149+
: `${followersCount.toLocaleString("en")} followers`}
150+
</a>
148151
</span>{" "}
149152
&middot;{" "}
150153
<span>
@@ -206,6 +209,41 @@ app.get("/", async (c) => {
206209
);
207210
});
208211

212+
app.get("/followers", async (c) => {
213+
const { bot } = c.env;
214+
const ctx = bot.federation.createContext(c.req.raw, c.env.contextData);
215+
const session = bot.getSession(ctx);
216+
const followersCount = await bot.repository.countFollowers();
217+
const followers = await Array.fromAsync(bot.repository.getFollowers());
218+
219+
const url = new URL(c.req.url);
220+
const activityLink = ctx.getActorUri(bot.identifier);
221+
const feedLink = new URL("/feed.xml", url);
222+
223+
return c.html(
224+
<Layout
225+
bot={bot}
226+
host={url.host}
227+
activityLink={activityLink}
228+
feedLink={feedLink}
229+
>
230+
<header class="container">
231+
<h1>
232+
<a href="/">&larr;</a>{" "}
233+
{followersCount === 1
234+
? `1 follower`
235+
: `${followersCount.toLocaleString("en")} followers`}
236+
</h1>
237+
</header>
238+
<main class="container">
239+
{followers.map((follower, index) => (
240+
<Follower key={follower.id?.href ?? index} actor={follower} session={session} />
241+
))}
242+
</main>
243+
</Layout>,
244+
);
245+
});
246+
209247
app.get("/tags/:hashtag", async (c) => {
210248
const hashtag = c.req.param("hashtag");
211249
const { bot } = c.env;

0 commit comments

Comments
 (0)