From 70fffbf55d2024cd2d2156d02d62da708b14c488 Mon Sep 17 00:00:00 2001 From: aeroreyna Date: Mon, 4 Apr 2022 21:30:41 -0700 Subject: [PATCH] add actor in internal notifications --- dbTools/profile.js | 5 +++-- notifications.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dbTools/profile.js b/dbTools/profile.js index 8fb86cd..2992604 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -229,7 +229,7 @@ userDB = (DB) => { }); } - DB.addNotification = async (profileid, message, postid, commentIndx) => { + DB.addNotification = async (profileid, message, postid, commentIndx, actorid) => { const _id = DB.ObjectID(profileid); let update = { $push:{ @@ -237,7 +237,8 @@ userDB = (DB) => { ts: new Date(), body: message, postid, - commentIndx + commentIndx, + actorid, } } } diff --git a/notifications.js b/notifications.js index bc29a74..bde45e1 100644 --- a/notifications.js +++ b/notifications.js @@ -321,7 +321,7 @@ const Notifications = { if (bookedProfile._id == senderProfile._id) return 0; const notifBody = `${senderProfile.profile.firstName} commented in a post you follow`; sendPushNotification(bookedProfile.token, notifBody, {}); - DB.addNotification(bookedProfile._id, notifBody, post._id, post.comments.length - 1); + DB.addNotification(bookedProfile._id, notifBody, post._id, post.comments.length - 1, senderProfile._id); yourBookmarkedPostGotACommentTemplate(post, userEmail, postProfile, senderProfile, bookedProfile, message); }); }, @@ -337,7 +337,7 @@ const Notifications = { if (postProfile.isCourse || senderProfile._id == postProfile._id) return 0; //Course owners do not need to receive notifs const notifBody = `${senderProfile.profile.firstName} commented in your post`; sendPushNotification(postProfile.token, notifBody, {}); - DB.addNotification(post.profileid, notifBody, postId, post.comments.length - 1); + DB.addNotification(post.profileid, notifBody, postId, post.comments.length - 1, senderProfile._id); return youGotANewPostCommentTemplate(post, userEmail, postProfile, senderProfile, message); }, async yourGroupGotANewPost(groupProfile, senderProfile, message, post) { @@ -355,7 +355,7 @@ const Notifications = { if (userProfile._id == senderProfile._id) return 0; //avoid sending self notifications const notifBody = `${senderProfile.profile.firstName} post in the group ${groupProfile.profile.firstName} ${groupProfile.profile.lastName}`; sendPushNotification(userProfile.token, notifBody, {}); - DB.addNotification(userProfile._id, notifBody, post._id); + DB.addNotification(userProfile._id, notifBody, post._id, null, senderProfile._id); yourGroupGotANewPostTemplate(groupProfile, userEmail, userProfile, senderProfile, message); }); }, @@ -376,7 +376,7 @@ const Notifications = { } const notifBody = `${senderProfile.profile.firstName} post in your profile`; sendPushNotification(profile.token, notifBody, {}); - DB.addNotification(toProfileId, notifBody, post._id); + DB.addNotification(toProfileId, notifBody, post._id, null, senderProfile._id); return youGotANewPostTemplate(profile, user.username, senderProfile, message); }, youHaveAnInvitation,