Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor notification bug fixes #593

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions desci-server/src/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export const emitNotificationForAnnotation = async (annotationId: number) => {
}

const annotationAuthor = annotation.author;
const annotationAuthorName = annotationAuthor?.name || 'A user';
const node = annotation.node || annotation.attestation?.node;
const nodeOwner = node?.owner;

Expand All @@ -250,26 +251,29 @@ export const emitNotificationForAnnotation = async (annotationId: number) => {
return;
}

const dotlessUuid = node.uuid.replace(/\./g, '');

const notificationData: CreateNotificationData = {
userId: nodeOwner.id,
type: NotificationType.COMMENTS,
title: `${annotationAuthor?.name} commented on your research object`,
title: `${annotationAuthorName} commented on your research object`,
message: `Your research object titled ${node.title}, has received a new comment.`, // TODO:: Ideally deserialize some of the message body from the annotation and show a truncated snippet
nodeUuid: node.uuid,
payload: { type: NotificationType.COMMENTS, nodeUuid: node.uuid, annotationId } as CommentPayload,
payload: { type: NotificationType.COMMENTS, nodeUuid: dotlessUuid, annotationId } as CommentPayload,
};

await createUserNotification(notificationData);
};
//
export const emitNotificationOnPublish = async (node: Node, user: User, dpid: string) => {
const dotlessUuid = node.uuid.replace(/\./g, '');
const notificationData: CreateNotificationData = {
userId: user.id,
type: NotificationType.PUBLISH,
title: `Your research object has been published!`,
message: `Your research object titled "${node.title}" has been published and is now available for public access.`,
nodeUuid: node.uuid,
payload: { type: NotificationType.PUBLISH, nodeUuid: node.uuid, dpid } as PublishPayload,
payload: { type: NotificationType.PUBLISH, nodeUuid: dotlessUuid, dpid } as PublishPayload,
};

await createUserNotification(notificationData);
Expand Down