diff --git a/dbTools/profile.js b/dbTools/profile.js index 88f1cab..71877b7 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -115,13 +115,15 @@ userDB = (DB) => { }); } - DB.addNotification = async (profileid, message) => { + DB.addNotification = async (profileid, message, postid, commentIndx) => { const _id = DB.ObjectID(profileid); let update = { $push:{ notifications: { ts: new Date(), - body: message + body: message, + postid, + commentIndx } } } diff --git a/notifications.js b/notifications.js index 8274307..3c6a047 100644 --- a/notifications.js +++ b/notifications.js @@ -131,6 +131,8 @@ const Notifications = { usersEmails.forEach((userEmail, index) => { const bookedProfile = subscribed[index]; if (bookedProfile._id == senderProfile._id) return 0; + const notifBody = `${senderProfile.profile.firstName} commented in a post you follow`; + DB.addNotification(bookedProfile._id, notifBody, post._id, post.comments.length - 1); yourBookmarkedPostGotACommentTemplate(post, userEmail, postProfile, senderProfile, bookedProfile, message); }); }, @@ -144,6 +146,8 @@ const Notifications = { this.yourBookmarkedPostGotAComment(post, postProfile, senderProfile, message) } 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`; + DB.addNotification(post.profileid, notifBody, postId, post.comments.length - 1); return youGotANewPostCommentTemplate(post, userEmail, postProfile, senderProfile, message); }, async yourGroupGotANewPost(groupProfile, senderProfile, message) { @@ -159,10 +163,15 @@ const Notifications = { users.forEach((userEmail, index) => { let userProfile = subscribed[index]; //who is this email sending to 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}`; + DB.addNotification(userProfile._id, notifBody, post._id); yourGroupGotANewPostTemplate(groupProfile, userEmail, userProfile, senderProfile, message); }); }, - async youGotANewPost(toProfileId, whoPostedId, message) { + async youGotANewPost(post) { + const toProfileId = post.toProfile; + const whoPostedId = post.profileid; + const message = post.content; const DB = await DBGetter.getDB; const profile = await DB.getProfileCache(toProfileId); const user = await DB.getUserById(profile.userid); @@ -170,6 +179,8 @@ const Notifications = { if (profile.isGroup) { return this.yourGroupGotANewPost(profile, senderProfile, message); } + const notifBody = `${senderProfile.profile.firstName} post in your profile`; + DB.addNotification(toProfileId, notifBody, post._id); return youGotANewPostTemplate(profile, user.username, senderProfile, message); } } diff --git a/routes/post.js b/routes/post.js index ec5ca37..8aca38d 100644 --- a/routes/post.js +++ b/routes/post.js @@ -50,7 +50,7 @@ DB.getDB.then((DB)=>{ post = postObj.toObj(); post._id = dbr.insertedId; if(post.toProfile && post.toProfile != post.profileid){ - Notifications.youGotANewPost(post.toProfile, post.profileid, post.content) + Notifications.youGotANewPost(post) } return res.json({ status: "ok",