From cfc0a7eb9879a372ee1c511f08d70de84f078247 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 refs https://linear.app/tryghost/issue/AP-286 We want to make sure that the original author is notified of the activity as well as our followers. This is wrapped in guards because it's possible the property doesn't exist. --- src/handlers.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/handlers.ts b/src/handlers.ts index 12f652f3..026b902a 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; @@ -121,6 +123,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 }); @@ -171,6 +183,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 });