mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Add incoming Like federation
This commit is contained in:
parent
17bd81cf46
commit
ae41139ad8
3 changed files with 48 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue