From f529ea395975dfb2be8e8e1ec9ddccf06403da28 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Thu, 5 Sep 2024 16:51:55 +0700 Subject: [PATCH] Sent Like/Unlike to the author of the object --- src/handlers.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/handlers.ts b/src/handlers.ts index 2c2030ac..7d6e6160 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -9,6 +9,7 @@ import { Create, Note, Update, + Actor, PUBLIC_COLLECTION } from '@fedify/fedify'; import { Context, Next } from 'hono'; @@ -22,6 +23,7 @@ import type { PersonData } from './user'; import { ACTOR_DEFAULT_HANDLE } from './constants'; import { Temporal } from '@js-temporal/polyfill'; import { createHash } from 'node:crypto'; +import { lookupActor } from 'lookup-helpers'; type StoredThing = { id: string; @@ -123,6 +125,16 @@ export async function unlikeAction( await removeFromList(ctx.get('db'), ['liked'], likeId!.href); await ctx.get('globaldb').delete([likeId!.href]); + let attributionActor: Actor | null = null; + if (objectToLike.attributionId) { + attributionActor = await lookupActor(apCtx, objectToLike.attributionId.href); + } + if (attributionActor) { + apCtx.sendActivity({ handle: ACTOR_DEFAULT_HANDLE }, attributionActor, undo, { + preferSharedInbox: true + }); + } + apCtx.sendActivity({ handle: ACTOR_DEFAULT_HANDLE }, 'followers', undo, { preferSharedInbox: true }); @@ -173,6 +185,16 @@ export async function likeAction( await addToList(ctx.get('db'), ['liked'], like.id!.href); + let attributionActor: Actor | null = null; + if (objectToLike.attributionId) { + attributionActor = await lookupActor(apCtx, objectToLike.attributionId.href); + } + if (attributionActor) { + apCtx.sendActivity({ handle: ACTOR_DEFAULT_HANDLE }, attributionActor, like, { + preferSharedInbox: true + }); + } + apCtx.sendActivity({ handle: ACTOR_DEFAULT_HANDLE }, 'followers', like, { preferSharedInbox: true });