mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Add more federation support with Undo objects
This commit is contained in:
parent
ae41139ad8
commit
1db82202e0
|
|
@ -46,3 +46,30 @@ export const createLike = async (
|
|||
// TODO: Add database jobs for federating this
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteLike = async (
|
||||
user: UserWithRelations,
|
||||
status: StatusWithRelations
|
||||
) => {
|
||||
await client.like.deleteMany({
|
||||
where: {
|
||||
likedId: status.id,
|
||||
likerId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
// Notify the user that their post has been favourited
|
||||
await client.notification.deleteMany({
|
||||
where: {
|
||||
accountId: user.id,
|
||||
type: "favourite",
|
||||
notifiedId: status.authorId,
|
||||
statusId: status.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (user.instanceId === null) {
|
||||
// User is local, federate the delete
|
||||
// TODO: Federate this
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { applyConfig } from "@api";
|
|||
import { errorResponse, jsonResponse } from "@response";
|
||||
import type { MatchedRoute } from "bun";
|
||||
import { client } from "~database/datasource";
|
||||
import { deleteLike } from "~database/entities/Like";
|
||||
import {
|
||||
isViewableByUser,
|
||||
statusAndUserRelations,
|
||||
|
|
@ -46,12 +47,7 @@ export default async (
|
|||
if (!status || !isViewableByUser(status, user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
||||
await client.like.deleteMany({
|
||||
where: {
|
||||
likedId: status.id,
|
||||
likerId: user.id,
|
||||
},
|
||||
});
|
||||
await deleteLike(user, status);
|
||||
|
||||
return jsonResponse({
|
||||
...(await statusToAPI(status, user)),
|
||||
|
|
|
|||
|
|
@ -7,7 +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 { createLike, deleteLike } from "~database/entities/Like";
|
||||
import { createFromObject } from "~database/entities/Object";
|
||||
import {
|
||||
createNewStatus,
|
||||
|
|
@ -21,6 +21,7 @@ import type {
|
|||
LysandAction,
|
||||
LysandPublication,
|
||||
Patch,
|
||||
Undo,
|
||||
} from "~types/lysand/Object";
|
||||
|
||||
export const meta = applyConfig({
|
||||
|
|
@ -274,6 +275,10 @@ export default async (
|
|||
case "Dislike": {
|
||||
// Store the object in the LysandObject table
|
||||
await createFromObject(body);
|
||||
|
||||
return jsonResponse({
|
||||
info: "Dislikes are not supported by this software",
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "Follow": {
|
||||
|
|
@ -332,8 +337,61 @@ export default async (
|
|||
break;
|
||||
}
|
||||
case "Undo": {
|
||||
const undo = body as Undo;
|
||||
// Store the object in the LysandObject table
|
||||
await createFromObject(body);
|
||||
|
||||
const object = await client.lysandObject.findUnique({
|
||||
where: {
|
||||
uri: undo.object,
|
||||
},
|
||||
});
|
||||
|
||||
if (!object) {
|
||||
return errorResponse("Object not found", 404);
|
||||
}
|
||||
|
||||
switch (object.type) {
|
||||
case "Like": {
|
||||
const status = await client.status.findUnique({
|
||||
where: {
|
||||
uri: undo.object,
|
||||
authorId: author.id,
|
||||
},
|
||||
include: statusAndUserRelations,
|
||||
});
|
||||
|
||||
if (!status) {
|
||||
return errorResponse("Status not found", 404);
|
||||
}
|
||||
|
||||
await deleteLike(author, status);
|
||||
break;
|
||||
}
|
||||
case "Announce": {
|
||||
await client.status.delete({
|
||||
where: {
|
||||
uri: undo.object,
|
||||
authorId: author.id,
|
||||
},
|
||||
include: statusAndUserRelations,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "Note": {
|
||||
await client.status.delete({
|
||||
where: {
|
||||
uri: undo.object,
|
||||
authorId: author.id,
|
||||
},
|
||||
include: statusAndUserRelations,
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return errorResponse("Invalid object type", 400);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Extension": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue