From b29211c3878b9470c41616070e6e03b8f2bfecaf Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 22 Oct 2024 11:11:52 +0200 Subject: [PATCH] Sort of following now --- src/database/index.ts | 9 +++++++++ src/database/init/09-create-follow.sql | 9 +++++++++ src/database/query/delete-follow.sql | 6 ++++++ src/database/query/put-follow.sql | 7 +++++++ src/dv/index.ts | 28 +++++++++++++++++--------- 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/database/init/09-create-follow.sql create mode 100644 src/database/query/delete-follow.sql create mode 100644 src/database/query/put-follow.sql diff --git a/src/database/index.ts b/src/database/index.ts index 4bce443..1d7af3f 100644 --- a/src/database/index.ts +++ b/src/database/index.ts @@ -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 { + l.info`Putting follow: from ${follower} to ${followed}` + + await this.#doQueryFile("src/database/query/put-follow.sql", [follower, followed]) + } } diff --git a/src/database/init/09-create-follow.sql b/src/database/init/09-create-follow.sql new file mode 100644 index 0000000..4864644 --- /dev/null +++ b/src/database/init/09-create-follow.sql @@ -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 + ) +); diff --git a/src/database/query/delete-follow.sql b/src/database/query/delete-follow.sql new file mode 100644 index 0000000..6637479 --- /dev/null +++ b/src/database/query/delete-follow.sql @@ -0,0 +1,6 @@ +DELETE FROM + follow +WHERE + follow.follower = $1 + AND + follow.followed = $2; \ No newline at end of file diff --git a/src/database/query/put-follow.sql b/src/database/query/put-follow.sql new file mode 100644 index 0000000..c3f810a --- /dev/null +++ b/src/database/query/put-follow.sql @@ -0,0 +1,7 @@ +INSERT INTO follow ( + follower, + followed +) VALUES ( + $1, + $2 +) ON CONFLICT DO NOTHING; diff --git a/src/dv/index.ts b/src/dv/index.ts index 31170b3..082f040 100644 --- a/src/dv/index.ts +++ b/src/dv/index.ts @@ -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, + })) } }