Add reblog and reply notifications

This commit is contained in:
Jesse Wierzbinski 2023-11-23 08:35:43 -10:00
parent be9b2e3376
commit 82162fccf4
No known key found for this signature in database
3 changed files with 61 additions and 0 deletions

View file

@ -436,6 +436,19 @@ export const createNewStatus = async (data: {
include: statusAndUserRelations, include: statusAndUserRelations,
}); });
// Create notification
if (status.inReplyToPost) {
await client.notification.create({
data: {
notifiedId: status.inReplyToPost.authorId,
accountId: status.authorId,
type: "mention",
statusId: status.id,
},
});
}
return status; return status;
}; };

View file

@ -83,6 +83,18 @@ export default async (
include: statusAndUserRelations, include: statusAndUserRelations,
}); });
// Create notification for reblog if reblogged user is on the same instance
if (status.reblog?.author.instanceId === user.instanceId) {
await client.notification.create({
data: {
accountId: user.id,
notifiedId: status.reblog.authorId,
type: "reblog",
statusId: status.reblogId,
},
});
}
return jsonResponse( return jsonResponse(
await statusToAPI( await statusToAPI(
{ {

View file

@ -15,6 +15,7 @@ import {
} from "~database/entities/Status"; } from "~database/entities/Status";
import { parseMentionsUris, userRelations } from "~database/entities/User"; import { parseMentionsUris, userRelations } from "~database/entities/User";
import type { import type {
Announce,
LysandAction, LysandAction,
LysandPublication, LysandPublication,
Patch, Patch,
@ -274,8 +275,43 @@ export default async (
break; break;
} }
case "Announce": { case "Announce": {
const announce = body as Announce;
// Store the object in the LysandObject table // Store the object in the LysandObject table
await createFromObject(body); await createFromObject(body);
const rebloggedStatus = await client.status.findUnique({
where: {
uri: announce.object,
},
include: statusAndUserRelations,
});
if (!rebloggedStatus) {
return errorResponse("Status not found", 404);
}
// Create new reblog
const newReblog = await client.status.create({
data: {
authorId: author.id,
reblogId: rebloggedStatus.id,
isReblog: true,
uri: body.uri,
visibility: rebloggedStatus.visibility,
sensitive: false,
},
include: statusAndUserRelations,
});
// Create notification
await client.notification.create({
data: {
accountId: author.id,
notifiedId: rebloggedStatus.authorId,
type: "reblog",
statusId: rebloggedStatus.id,
},
});
break; break;
} }
case "Undo": { case "Undo": {