From 52617bbcec4738661b648b7dc1b6fc9887aecdcf Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Tue, 14 Sep 2021 11:57:42 -0700 Subject: [PATCH] notification on commets --- notifications.js | 41 ++++++++++++++++++++++++++++++++++++----- routes/post.js | 2 +- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/notifications.js b/notifications.js index cbd6d59..43c75cf 100644 --- a/notifications.js +++ b/notifications.js @@ -25,15 +25,46 @@ const Notifications = { console.log("Message sent: %s", info.messageId); }, - async youGotANewPost(toProfileId, whoPostedId, Message){ + async youGotANewPostComment(postId, whoPostedId, Message){ const DB = await DBGetter.getDB; - const profile = await DB.getProfileCache(toProfileId); + const post = await DB.getPost(postId) + const profile = await DB.getProfileCache(post.profileid); const user = await DB.getUserById(profile.userid); const senderProfile = await DB.getProfileCache(whoPostedId); - let subject = senderProfile.profile.firstName + " post on your profile"; + let subject = senderProfile.profile.firstName + " comment on your post"; let message = `

Hello ${profile.profile.firstName},

+

You got a comment on your post:

+ +
+

${post.content}

+
+
— You
+ +

Comment:

+ +
+

${Message}

+
+
— ${senderProfile.profile.firstName} ${senderProfile.profile.lastName}
+ +

Check it on the site

+ +

Blessings

+ +`; + this.sendEmail(user.username, subject, message) + }, + async youGotANewPost(toProfileId, whoPostedId, Message){ + const DB = await DBGetter.getDB; + const profile = await DB.getProfileCache(toProfileId); + const user = await DB.getUserById(profile.userid); + const senderProfile = await DB.getProfileCache(whoPostedId); + let subject = senderProfile.profile.firstName + " post on your profile"; + let message = ` +

Hello ${profile.profile.firstName},

+

You got a new post:

@@ -46,8 +77,8 @@ const Notifications = {

Blessings

`; - this.sendEmail(user.username, subject, message) - } + this.sendEmail(user.username, subject, message) + } } module.exports = Notifications \ No newline at end of file diff --git a/routes/post.js b/routes/post.js index 56679c9..2fe9178 100644 --- a/routes/post.js +++ b/routes/post.js @@ -77,7 +77,7 @@ DB.getDB.then((DB)=>{ lastUpdated: new Date(), reactions: {} } - console.log("comment", postid, comment); + Notifications.youGotANewPostComment(postid, profileid, content) r = await DB.newComment(postid, comment); return res.json({ status: "ok",