send accept to follow request

This commit is contained in:
Moon Man 2023-12-27 11:17:09 -05:00
parent 56c77e078f
commit e98d6f75c8
1 changed files with 27 additions and 8 deletions

View File

@ -40,7 +40,7 @@ export const handleInboxPost = async (req: Request, res: Response) => {
if (actor) {
const followerUrl: string = activity.actor;
const signer = await getUserById(1);
const signer = actor;
if (!signer) {
res.status(500).end();
@ -75,10 +75,9 @@ export const handleInboxPost = async (req: Request, res: Response) => {
return;
}
await addFollower(actor.id, follower.id, follower.preferredUsername, follower.name, follower.inbox, follower.endpoints?.sharedInbox);
await sendAccept(actor, follower.id, follower.inbox);
const response = {
};
await addFollower(actor.id, follower.id, follower.preferredUsername, follower.name, follower.inbox, follower.endpoints?.sharedInbox);
console.log("Done handling inbox POST follow request");
res.status(200);
@ -188,6 +187,26 @@ export const createArticleObject = (article: Article, nickname: string) => {
return obj;
};
export const sendAccept = async (user: User, follower: string, inbox: string) => {
const actor = fillRoute("actor", user.nickname);
const activity = {
id: fillRoute("activity", Date.now() * 1_000_000),
"@context": CONTEXT,
type: "Accept",
actor,
object: follower
};
const payload = JSON.stringify(activity, null, 4);
const hash = hashDigest(payload);
const init: RequestInit = { method: "POST", body: payload };
const init2 = { hash, privateKey: user.private_key, keyId: getKeyId(user.nickname) };
await signedFetch(inbox, init, init2);
};
export const sendAll = async (keyId: string, privateKey: string, activity: Record<string, any> | string, inboxes: string[]) => {
activity = typeof activity === "string"
? activity