feat(federation): Add inbound Reaction processing

This commit is contained in:
Jesse Wierzbinski 2025-05-28 16:50:59 +02:00
parent 1fba91f772
commit e0adaca2a2
No known key found for this signature in database
2 changed files with 102 additions and 5 deletions

View file

@ -1,5 +1,12 @@
import { getLogger, type Logger } from "@logtape/logtape";
import { type Instance, Like, Note, Relationship, User } from "@versia/kit/db";
import {
type Instance,
Like,
Note,
Reaction,
Relationship,
User,
} from "@versia/kit/db";
import { Likes, Notes } from "@versia/kit/tables";
import type { SocketAddress } from "bun";
import { Glob } from "bun";
@ -198,8 +205,9 @@ export class InboxProcessor {
InboxProcessor.processDelete(d),
)
.on(VersiaEntities.User, (u) => InboxProcessor.processUser(u))
.on(VersiaEntities.Share, async (s) =>
InboxProcessor.processShare(s),
.on(VersiaEntities.Share, (s) => InboxProcessor.processShare(s))
.on(VersiaEntities.Reaction, (r) =>
InboxProcessor.processReaction(r),
)
.sort(() => {
throw new ApiError(400, "Unknown entity type");
@ -209,6 +217,29 @@ export class InboxProcessor {
}
}
/**
* Handles Reaction entity processing
*
* @param {VersiaEntities.Reaction} reaction - The Reaction entity to process.
* @returns {Promise<void>}
*/
private static async processReaction(
reaction: VersiaEntities.Reaction,
): Promise<void> {
const author = await User.resolve(new URL(reaction.data.author));
const note = await Note.resolve(new URL(reaction.data.object));
if (!author) {
throw new ApiError(404, "Author not found");
}
if (!note) {
throw new ApiError(404, "Note not found");
}
await Reaction.fromVersia(reaction, author, note);
}
/**
* Handles Note entity processing
*