MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / notifyUsers

Function notifyUsers

apps/app-server/src/utils/notifications.ts:32–89  ·  view source on GitHub ↗
(
  notifications: {
    type: DeepNotesNotificationType;

    recipients: Record<string, { encryptedSymmetricKey: Uint8Array }>;

    encryptedContent: Uint8Array;
  }[],
)

Source from the content-addressed store, hash-verified

30export type NotificationsResponse = z.infer<typeof notificationsResponseSchema>;
31
32export async function notifyUsers(
33 notifications: {
34 type: DeepNotesNotificationType;
35
36 recipients: Record<string, { encryptedSymmetricKey: Uint8Array }>;
37
38 encryptedContent: Uint8Array;
39 }[],
40) {
41 await dataAbstraction().transaction(async ({ trx }) => {
42 const dateTime = new Date();
43
44 await Promise.all(
45 notifications.map(async ({ recipients, type, encryptedContent }) => {
46 const notificationId = parseInt(
47 (
48 await NotificationModel.query(trx)
49 .insert({
50 type,
51
52 encrypted_content: encryptedContent,
53
54 datetime: dateTime,
55 })
56 .returning('id')
57 ).id as any,
58 );
59
60 await Promise.all(
61 objEntries(recipients).map(
62 async ([userId, { encryptedSymmetricKey }]) => {
63 await UserNotificationModel.query(trx).insert({
64 user_id: userId,
65 notification_id: notificationId,
66
67 encrypted_symmetric_key: encryptedSymmetricKey,
68 });
69
70 await getRedis().publish(
71 `user-notification:${userId}`,
72 pack({
73 id: notificationId,
74
75 type,
76
77 encryptedSymmetricKey: encryptedSymmetricKey,
78 encryptedContent: encryptedContent,
79
80 dateTime,
81 } as DeepNotesNotification),
82 );
83 },
84 ),
85 );
86 }),
87 );
88 });
89}

Callers 10

changeUserRoleStep2Function · 0.90
removeUserStep2Function · 0.90
acceptStep2Function · 0.90
rejectStep2Function · 0.90
sendStep2Function · 0.90
cancelStep2Function · 0.90
acceptStep2Function · 0.90
rejectStep2Function · 0.90
sendStep2Function · 0.90
cancelStep2Function · 0.90

Calls 3

objEntriesFunction · 0.90
transactionMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected