feat(api): Add notifications for follow requests again and mentions

This commit is contained in:
Jesse Wierzbinski 2024-04-15 19:40:35 -10:00
parent 06bcbbe451
commit 47133ac3fe
No known key found for this signature in database
4 changed files with 138 additions and 5 deletions

View file

@ -35,6 +35,7 @@ import {
status,
statusToMentions,
user,
notification,
} from "~drizzle/schema";
import { LogLevel } from "~packages/log-manager";
import type { Note } from "~types/lysand/Object";
@ -995,6 +996,18 @@ export const createNewStatus = async (
.where(inArray(attachment.id, media_attachments));
}
// Send notifications for mentioned local users
for (const mention of mentions ?? []) {
if (mention.instanceId === null) {
await db.insert(notification).values({
accountId: author.id,
notifiedId: mention.id,
type: "mention",
statusId: newStatus.id,
});
}
}
return (
(await findFirstStatuses({
where: (status, { eq }) => eq(status.id, newStatus.id),
@ -1146,6 +1159,18 @@ export const editStatus = async (
.execute();
}
// Send notifications for mentioned local users
for (const mention of mentions ?? []) {
if (mention.instanceId === null) {
await db.insert(notification).values({
accountId: statusToEdit.authorId,
notifiedId: mention.id,
type: "mention",
statusId: updated.id,
});
}
}
// Set attachment parents
await db
.update(attachment)

View file

@ -172,7 +172,7 @@ export const followRequestUser = async (
notify = false,
languages: string[] = [],
): Promise<InferSelectModel<typeof relationship>> => {
const isRemote = follower.instanceId !== followee.instanceId;
const isRemote = followee.instanceId !== null;
const updatedRelationship = (
await db
@ -226,9 +226,9 @@ export const followRequestUser = async (
}
} else {
await db.insert(notification).values({
accountId: followee.id,
accountId: follower.id,
type: followee.isLocked ? "follow_request" : "follow",
notifiedId: follower.id,
notifiedId: followee.id,
});
}