Add incoming Like federation

This commit is contained in:
Jesse Wierzbinski 2023-11-23 08:43:56 -10:00
parent 17bd81cf46
commit ae41139ad8
No known key found for this signature in database
3 changed files with 48 additions and 6 deletions

View file

@ -2,6 +2,9 @@
import type { Like as LysandLike } from "~types/lysand/Object";
import { getConfig } from "@config";
import type { Like } from "@prisma/client";
import { client } from "~database/datasource";
import type { UserWithRelations } from "./User";
import type { StatusWithRelations } from "./Status";
/**
* Represents a Like entity in the database.
@ -17,3 +20,29 @@ export const toLysand = (like: Like): LysandLike => {
uri: `${getConfig().http.base_url}/actions/${like.id}`,
};
};
export const createLike = async (
user: UserWithRelations,
status: StatusWithRelations
) => {
await client.like.create({
data: {
likedId: status.id,
likerId: user.id,
},
});
if (status.author.instanceId === user.instanceId) {
// Notify the user that their post has been favourited
await client.notification.create({
data: {
accountId: user.id,
type: "favourite",
notifiedId: status.authorId,
statusId: status.id,
},
});
} else {
// TODO: Add database jobs for federating this
}
};