Some progress towards accepting and rejecting follows #3
5 changed files with 50 additions and 9 deletions
|
@ -108,6 +108,9 @@ export class Database {
|
|||
]
|
||||
)
|
||||
|
||||
l.info`09/XX Creating follow table...`
|
||||
await this.#doQueryFile("src/database/init/09-create-follow.sql")
|
||||
|
||||
l.info("Done!")
|
||||
}
|
||||
|
||||
|
@ -173,4 +176,10 @@ export class Database {
|
|||
|
||||
return result
|
||||
}
|
||||
|
||||
async putFollow(follower: string, followed: string): Promise<void> {
|
||||
l.info`Putting follow: from ${follower} to ${followed}`
|
||||
|
||||
await this.#doQueryFile<void>("src/database/query/put-follow.sql", [follower, followed])
|
||||
}
|
||||
}
|
||||
|
|
9
src/database/init/09-create-follow.sql
Normal file
9
src/database/init/09-create-follow.sql
Normal file
|
@ -0,0 +1,9 @@
|
|||
CREATE TABLE follow (
|
||||
follower VARCHAR REFERENCES (actor.handle) NOT NULL,
|
||||
followed VARCHAR REFERENCES (actor.handle) NOT NULL,
|
||||
|
||||
PRIMARY KEY (
|
||||
follower,
|
||||
followed
|
||||
)
|
||||
);
|
6
src/database/query/delete-follow.sql
Normal file
6
src/database/query/delete-follow.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
DELETE FROM
|
||||
follow
|
||||
WHERE
|
||||
follow.follower = $1
|
||||
AND
|
||||
follow.followed = $2;
|
7
src/database/query/put-follow.sql
Normal file
7
src/database/query/put-follow.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
INSERT INTO follow (
|
||||
follower,
|
||||
followed
|
||||
) VALUES (
|
||||
$1,
|
||||
$2
|
||||
) ON CONFLICT DO NOTHING;
|
|
@ -1,5 +1,5 @@
|
|||
// deno-lint-ignore-file require-await
|
||||
import { createFederation, Person, Application, Image, PropertyValue, Organization, Federation, KvStore, Context, Actor, Follow, Endpoints, importSpki, importJwk, NodeInfo } from "@fedify/fedify"
|
||||
import { createFederation, Person, Application, Image, PropertyValue, Organization, Federation, KvStore, Context, Actor, Follow, Endpoints, importSpki, importJwk, NodeInfo, Accept } 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"
|
||||
|
@ -307,27 +307,37 @@ export class DotinoVeloce {
|
|||
return
|
||||
}
|
||||
|
||||
l.debug`Attempting to determine object of the follow request...` // TODO: ???
|
||||
l.debug`Attempting to determine what is being followed...`
|
||||
const object = ctx.parseUri(follow.objectId)
|
||||
l.debug`Object is: ${object}`
|
||||
|
||||
if(!object) {
|
||||
l.warn`Failed to determine object, skipping.`
|
||||
l.warn`Failed to determine what is being followed, skipping.`
|
||||
return
|
||||
}
|
||||
if(object.type !== "actor") {
|
||||
l.warn`Object type is not actor, skipping.` // TODO: Why?
|
||||
l.warn`Attempting to follow something that is not actor, skipping.`
|
||||
return
|
||||
}
|
||||
|
||||
l.debug`Attempting to determine actor of the follow request...`
|
||||
l.debug`Attempting to determine who sent 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}`
|
||||
if(!actor) {
|
||||
l.warn`Failed to determine who sent the follow request, skipping.`
|
||||
return
|
||||
}
|
||||
if(object.type !== "actor") {
|
||||
l.warn`Being followed by someone who isn't an actor, skipping.`
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
l.info`Accepting follow request from ${follow.actorId} to ${follow.objectId}...`
|
||||
await ctx.sendActivity(object, "followers", new Accept({
|
||||
object: follow,
|
||||
actor: follow.objectId,
|
||||
to: follow.actorId,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue