followsOf

tcmts.hub.followsOf · #dykd6njw · term · runs anywhere

The DIDs someone follows on Bluesky, as the AppView says (app.bsky.graph.getFollows), up to a few thousand.

import { cached, hubServices } from "#codebase/tcmts/hub";

export function followsOf(did: string): Promise<Set<string>> {
  return cached(`follows ${did}`, async () => {
    const out = new Set<string>();
    const { appview } = await hubServices();
    let cursor: string | undefined;
    for (let page = 0; page < 30; page++) {
      const q = new URLSearchParams({ actor: did, limit: "100", ...(cursor ? { cursor } : {}) });
      const res = await fetch(`${appview}/xrpc/app.bsky.graph.getFollows?${q}`);
      if (!res.ok) break;
      const got = (await res.json()) as { follows?: { did: string }[]; cursor?: string };
      for (const f of got.follows ?? []) out.add(f.did);
      cursor = got.follows?.length ? got.cursor : undefined;
      if (!cursor) break;
    }
    return out;
  });
}

uses

used by