mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 22:09: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
|
|
@ -3,6 +3,7 @@ import { applyConfig } from "@api";
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import type { MatchedRoute } from "bun";
|
||||
import { client } from "~database/datasource";
|
||||
import { createLike } from "~database/entities/Like";
|
||||
import {
|
||||
isViewableByUser,
|
||||
statusAndUserRelations,
|
||||
|
|
@ -54,12 +55,7 @@ export default async (
|
|||
});
|
||||
|
||||
if (!existingLike) {
|
||||
await client.like.create({
|
||||
data: {
|
||||
likedId: status.id,
|
||||
likerId: user.id,
|
||||
},
|
||||
});
|
||||
await createLike(user, status);
|
||||
}
|
||||
|
||||
return jsonResponse({
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { errorResponse, jsonResponse } from "@response";
|
|||
import type { MatchedRoute } from "bun";
|
||||
import { client } from "~database/datasource";
|
||||
import { parseEmojis } from "~database/entities/Emoji";
|
||||
import { createLike } from "~database/entities/Like";
|
||||
import { createFromObject } from "~database/entities/Object";
|
||||
import {
|
||||
createNewStatus,
|
||||
|
|
@ -16,6 +17,7 @@ import {
|
|||
import { parseMentionsUris, userRelations } from "~database/entities/User";
|
||||
import type {
|
||||
Announce,
|
||||
Like,
|
||||
LysandAction,
|
||||
LysandPublication,
|
||||
Patch,
|
||||
|
|
@ -250,8 +252,23 @@ export default async (
|
|||
break;
|
||||
}
|
||||
case "Like": {
|
||||
const like = body as Like;
|
||||
// Store the object in the LysandObject table
|
||||
await createFromObject(body);
|
||||
|
||||
const likedStatus = await client.status.findUnique({
|
||||
where: {
|
||||
uri: like.object,
|
||||
},
|
||||
include: statusAndUserRelations,
|
||||
});
|
||||
|
||||
if (!likedStatus) {
|
||||
return errorResponse("Status not found", 404);
|
||||
}
|
||||
|
||||
await createLike(author, likedStatus);
|
||||
|
||||
break;
|
||||
}
|
||||
case "Dislike": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue