Skip to content

Commit

Permalink
Sent Like/Unlike to the author of the object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
allouis committed Sep 9, 2024
1 parent d38ddb8 commit cfc0a7e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Create,
Note,
Update,
Actor,
PUBLIC_COLLECTION
} from '@fedify/fedify';
import { Context, Next } from 'hono';
Expand All @@ -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;
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down

0 comments on commit cfc0a7e

Please sign in to comment.