From 82162fccf4dde8039100f9599648b6ab8b709eb0 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 23 Nov 2023 08:35:43 -1000 Subject: [PATCH] Add reblog and reply notifications --- database/entities/Status.ts | 13 ++++++++ server/api/api/v1/statuses/[id]/reblog.ts | 12 ++++++++ server/api/users/[uuid]/inbox/index.ts | 36 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/database/entities/Status.ts b/database/entities/Status.ts index 1708e788..1934a002 100644 --- a/database/entities/Status.ts +++ b/database/entities/Status.ts @@ -436,6 +436,19 @@ export const createNewStatus = async (data: { 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; }; diff --git a/server/api/api/v1/statuses/[id]/reblog.ts b/server/api/api/v1/statuses/[id]/reblog.ts index 6a05273b..32096db3 100644 --- a/server/api/api/v1/statuses/[id]/reblog.ts +++ b/server/api/api/v1/statuses/[id]/reblog.ts @@ -83,6 +83,18 @@ export default async ( 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( await statusToAPI( { diff --git a/server/api/users/[uuid]/inbox/index.ts b/server/api/users/[uuid]/inbox/index.ts index c04416b9..daea01c0 100644 --- a/server/api/users/[uuid]/inbox/index.ts +++ b/server/api/users/[uuid]/inbox/index.ts @@ -15,6 +15,7 @@ import { } from "~database/entities/Status"; import { parseMentionsUris, userRelations } from "~database/entities/User"; import type { + Announce, LysandAction, LysandPublication, Patch, @@ -274,8 +275,43 @@ export default async ( break; } case "Announce": { + const announce = body as Announce; // Store the object in the LysandObject table 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; } case "Undo": {