Some progress towards accepting and rejecting follows #3

Merged
steffo merged 22 commits from feature/follows into main 2024-10-23 05:47:18 +00:00
Showing only changes of commit 292d3d3e7d - Show all commits

View file

@ -1,5 +1,5 @@
// deno-lint-ignore-file require-await
import { createFederation, Person, Application, Image, PropertyValue, Organization, Federation, KvStore, Context, Actor } from "@fedify/fedify"
import { createFederation, Person, Application, Image, PropertyValue, Organization, Federation, KvStore, Context, Actor, Follow } from "@fedify/fedify"
import { getLogger } from "https://jsr.io/@logtape/logtape/0.6.3/logtape/logger.ts"
import { escapeHtml } from "@@x/escape"
import { StratzAPI } from "../stratz/api.ts"
@ -17,9 +17,16 @@ export class DotinoVeloce {
constructor(kv: KvStore, stratz: StratzAPI) {
this.stratz = stratz
this.federation = createFederation<ContextData>({ kv })
this.federation.setInboxListeners("/inbox/{identifier}", /* We don't need shared inboxes here. */)
this.federation.setActorDispatcher("/users/{identifier}", this.#actorHandler)
this.federation
.setActorDispatcher("/users/{identifier}", this.#actorHandler.bind(this))
.mapHandle(this.#actorMapper.bind(this))
this.federation
.setInboxListeners("/inbox/{identifier}", "/inbox")
.on(Follow, this.#followHandler.bind(this))
}
#commonActorProperties(ctx: Context<ContextData>, handle: string): Partial<Actor> {
@ -187,14 +194,56 @@ export class DotinoVeloce {
}
async #actorHandler(ctx: Context<ContextData>, handle: string) {
l.debug`Handling actor with handle: ${handle}`
l.info`Handling actor with handle: ${handle}`
let actor = null
actor ??= this.#serviceActor(ctx, handle)
actor ??= this.#playerActor(ctx, handle)
actor ??= this.#guildActor(ctx, handle)
actor ??= this.#serviceActor(ctx, handle)
return actor
}
async #actorMapper(_ctx: Context<ContextData>, handle: string) {
return handle
}
async #followHandler(ctx: Context<ContextData>, follow: Follow) {
l.info`Handling follow request: ${follow}`
if(!follow.id) {
l.warn`Missing follow ID, skipping.`
return
}
if(!follow.actorId) {
l.warn`Missing actor ID, skipping.`
return
}
if(!follow.objectId) {
l.warn`Missing object ID, skipping.`
return
}
l.debug`Attempting to determine object of the follow request...` // TODO: ???
const object = ctx.parseUri(follow.objectId)
l.debug`Object is: ${object}`
if(!object) {
l.warn`Failed to determine object, skipping.`
return
}
if(object.type !== "actor") {
l.warn`Object type is not actor, skipping.` // TODO: Why?
return
}
l.debug`Attempting to determine actor of the follow request...`
const actor = await follow.getActor(ctx)
l.debug`Actor is: ${actor}`
l.debug`Attempting to determine target of the follow request...`
const target = await follow.getTarget(ctx)
l.debug`Target is: ${target}`
}
}