hackers.pub 館

外交室(federation)

ja· en· ko
はじめての人へhackers.pubが外のサーバと手紙をやり取りする部屋。実務はfedifyに任せています。

holloと同じことが、Denoでもできます。外交の間取りを共有の設計図(builder)にしておけば、複数の棟から同じ配線を使い回せる——大きくなるアプリの、連合の置き場所の見本です。

inbox/mod.tsは、動詞の路線図として読めます。Accept、Follow、Undo……多義的な動詞は中身を見て振り分ける。届く手紙の種類が、一枚で見渡せます。

見どころ

  • 共有inboxは/ap/inbox、個別は/ap/actors/{identifier}/inbox。identifierはアカウントのUUIDか、インスタンスそのもののhostname
  • インスタンスactorは「Hackers’ Pub」というApplication。削除された住人はnullではなくKeyedTombstone(墓標)になる——リンクの先に、不在の形が残る
  • ハンドラはonPostCreated、onFollowed、onQuoteRequestedと名前つきの関数に分けられ、それぞれにテストが併設

経文の一節

builder
  .setInboxListeners("/ap/actors/{identifier}/inbox", "/ap/inbox")
  .setSharedKeyDispatcher((ctx) => ({
    identifier: new URL(ctx.canonicalOrigin).hostname,
  }))
  .onUnverifiedActivity(onUnverifiedActivity)
  .on(Accept, async (fedCtx, accept) => {
    if (await onQuoteRequestAccepted(fedCtx, accept)) return;
    if (await onRelayFollowAccepted(fedCtx, accept)) return;
    await onFollowAccepted(fedCtx, accept);
  })
federation/inbox/mod.ts L53-L63— Acceptが届いたら、三つの可能性を順に尋ねる

間取り

federation/builder.ts
空の設計図(createFederationBuilder)
federation/inbox/mod.ts
動詞の路線図。16種の.on()
federation/actor.ts
インスタンスactor/住人actor/墓標の三択
federation/mod.ts
副作用importで棟を組み上げて再輸出

となりの部屋

そとへのリンク