Unverified Commit 7958f755 authored by Hong Minhee's avatar Hong Minhee
Browse files

fedify inbox command is now more interoperable

parent 95c4a49c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -12,6 +12,13 @@ To be released.
    Instead, use the [x-forwarded-fetch] library to recognize the
    `X-Forwarded-Host` and `X-Forwarded-Proto` headers.

 -  Ephemeral actors and inboxes that the `fedify inbox` command spawns are
    now more interoperable with other ActivityPub implementations.

     -  Ephemeral actors now have the following properties: `summary`,
        `following`, `followers`, `outbox`, `manuallyApprovesFollowers`, and
        `url`.

[x-forwarded-fetch]: https://github.com/dahlia/x-forwarded-fetch


+34 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import {
  isActor,
  lookupObject,
  MemoryKvStore,
  type Recipient,
} from "@fedify/fedify";
import { getLogger } from "@logtape/logtape";
import { Hono } from "hono";
@@ -124,16 +125,22 @@ federation
      id: ctx.getActorUri(handle),
      preferredUsername: handle,
      name: "Fedify Ephemeral Inbox",
      summary: "An ephemeral ActivityPub inbox for testing purposes.",
      inbox: ctx.getInboxUri(handle),
      endpoints: new Endpoints({
        sharedInbox: ctx.getInboxUri(),
      }),
      followers: ctx.getFollowersUri(handle),
      following: ctx.getFollowingUri(handle),
      outbox: ctx.getOutboxUri(handle),
      manuallyApprovesFollowers: true,
      published: time,
      icon: new Image({
        url: new URL("https://fedify.dev/logo.png"),
        mediaType: "image/png",
      }),
      publicKey: key,
      url: ctx.getActorUri(handle),
    });
  })
  .setKeyPairDispatcher(async (_ctxData, handle) => {
@@ -162,6 +169,8 @@ async function acceptsFollowFrom(actor: Actor): Promise<boolean> {
  return false;
}

const followers: Record<string, Actor> = {};

federation
  .setInboxListeners("/{handle}/inbox", "/inbox")
  .on(Activity, async (ctx, activity) => {
@@ -176,7 +185,7 @@ federation
      const follower = await activity.getActor();
      if (!isActor(follower)) return;
      const accepts = await acceptsFollowFrom(follower);
      if (!accepts) {
      if (!accepts || activity.id == null) {
        logger.debug("Does not accept follow from {actor}.", {
          actor: follower.id?.href,
        });
@@ -185,6 +194,7 @@ federation
      logger.debug("Accepting follow from {actor}.", {
        actor: follower.id?.href,
      });
      followers[activity.id.href] = follower;
      await ctx.sendActivity(
        { handle },
        follower,
@@ -196,6 +206,29 @@ federation
    }
  });

federation
  .setFollowersDispatcher("/{handle}/followers", (_ctx, handle) => {
    if (handle !== "i") return null;
    const items: Recipient[] = [];
    for (const follower of Object.values(followers)) {
      if (follower.id == null) continue;
      items.push(follower);
    }
    return { items };
  })
  .setCounter((_ctx, handle) => {
    if (handle !== "i") return null;
    return Object.keys(followers).length;
  });

federation
  .setFollowingDispatcher("/{handle}/following", (_ctx, _handle) => null)
  .setCounter((_ctx, _handle) => 0);

federation
  .setOutboxDispatcher("/{handle}/outbox", (_ctx, _handle) => null)
  .setCounter((_ctx, _handle) => 0);

function printServerInfo(fedCtx: Context<number>): void {
  new Table(
    [
+1 −1
Original line number Diff line number Diff line
import type { Activity } from "@fedify/fedify";
import { getStatusText } from "@poppanator/http-constants";
import { getContextLoader, getDocumentLoader } from "../docloader.ts";
import { getContextLoader } from "../docloader.ts";

export async function renderRequest(request: Request): Promise<string> {
  request = request.clone();