Some progress towards accepting and rejecting follows #3
1 changed files with 54 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
// deno-lint-ignore-file require-await
|
// 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 { getLogger } from "https://jsr.io/@logtape/logtape/0.6.3/logtape/logger.ts"
|
||||||
import { escapeHtml } from "@@x/escape"
|
import { escapeHtml } from "@@x/escape"
|
||||||
import { StratzAPI } from "../stratz/api.ts"
|
import { StratzAPI } from "../stratz/api.ts"
|
||||||
|
@ -17,9 +17,16 @@ export class DotinoVeloce {
|
||||||
|
|
||||||
constructor(kv: KvStore, stratz: StratzAPI) {
|
constructor(kv: KvStore, stratz: StratzAPI) {
|
||||||
this.stratz = stratz
|
this.stratz = stratz
|
||||||
|
|
||||||
this.federation = createFederation<ContextData>({ kv })
|
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> {
|
#commonActorProperties(ctx: Context<ContextData>, handle: string): Partial<Actor> {
|
||||||
|
@ -187,14 +194,56 @@ export class DotinoVeloce {
|
||||||
}
|
}
|
||||||
|
|
||||||
async #actorHandler(ctx: Context<ContextData>, handle: string) {
|
async #actorHandler(ctx: Context<ContextData>, handle: string) {
|
||||||
l.debug`Handling actor with handle: ${handle}`
|
l.info`Handling actor with handle: ${handle}`
|
||||||
|
|
||||||
let actor = null
|
let actor = null
|
||||||
|
|
||||||
|
actor ??= this.#serviceActor(ctx, handle)
|
||||||
actor ??= this.#playerActor(ctx, handle)
|
actor ??= this.#playerActor(ctx, handle)
|
||||||
actor ??= this.#guildActor(ctx, handle)
|
actor ??= this.#guildActor(ctx, handle)
|
||||||
actor ??= this.#serviceActor(ctx, handle)
|
|
||||||
|
|
||||||
return actor
|
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}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue