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
  • Loading branch information
allouis committed Sep 5, 2024
1 parent f8c01eb commit c4c1d11
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 c4c1d11

Please sign in to comment.