diff --git a/dbTools/post.js b/dbTools/post.js index 6c36e99..f3a6e03 100644 --- a/dbTools/post.js +++ b/dbTools/post.js @@ -41,6 +41,32 @@ postDB = (DB)=>{ }); } + DB.bookmarkPost = async (postid, profileId)=>{ + const _id = DB.ObjectID(postid); + let update = { + $addToSet:{ + bookmarks: DB.ObjectID(profileId) + } + } + return DB.postCols.updateOne({_id}, update).catch((err)=>{ + console.log(err); + return false; + }); + } + + DB.unbookmarkPost = async (postid, profileId)=>{ + const _id = DB.ObjectID(postid); + let update = { + $pull:{ + bookmarks: DB.ObjectID(profileId) + } + } + return DB.postCols.updateOne({_id}, update).catch((err)=>{ + console.log(err); + return false; + }); + } + DB.newComment = (postid, comment) => { const id = DB.ObjectID(postid); return DB.postCols.updateOne({_id: id}, { diff --git a/def/post.js b/def/post.js index e900285..372e311 100644 --- a/def/post.js +++ b/def/post.js @@ -6,6 +6,7 @@ class Post { this.createdAt = info.createdAt || new Date(); this.reactions = info.reactions || {}; this.comments = info.comments || []; + this.bookmarks = info.bookmarks || []; //set profiles subscribed to this post //This should record edits this.contentHistory = info.contentHistory || []; this.toProfile = info.toProfile || ''; diff --git a/notifications.js b/notifications.js index 5c99a72..072ed32 100644 --- a/notifications.js +++ b/notifications.js @@ -25,7 +25,11 @@ const Notifications = { async youGotANewPostComment(postId, whoPostedId, message){ const DB = await DBGetter.getDB; const post = await DB.getPost(postId) + if(post.bookmarks){ + //send notification to boorkmaked profiles + } const profile = await DB.getProfileCache(post.profileid); + if(profile.isCourse) return 0; //Course owners do not need to receive notifs const user = await DB.getUserById(profile.userid); const senderProfile = await DB.getProfileCache(whoPostedId); let subject = senderProfile.profile.firstName + " comment on your post"; diff --git a/routes/post.js b/routes/post.js index 2fe9178..d3fda5f 100644 --- a/routes/post.js +++ b/routes/post.js @@ -44,23 +44,40 @@ DB.getDB.then((DB)=>{ }); router.post("/react", async (req, res) => { - let userid = getProfileId(req); + let profileid = getProfileId(req); let postid = req.body.postid; let reaction = { type: "like", createdAt: new Date() }; - r = await DB.newReaction(postid, userid, reaction); + r = await DB.newReaction(postid, profileid, reaction); return res.json({ status: "ok" }); }) router.post("/unreact", async (req, res) => { - let userid = getProfileId(req); + let profileid = getProfileId(req); let postid = req.body.postid; - r = await DB.removeReaction(postid, userid); - console.log(r) + r = await DB.removeReaction(postid, profileid); + return res.json({ + status: "ok" + }) + }); + + router.post("/bookmark", async (req, res) => { + let profileid = getProfileId(req); + let postid = req.body.postid; + r = await DB.bookmarkPost(postid, profileid); + return res.json({ + status: "ok" + }); + }) + + router.post("/unbookmark", async (req, res) => { + let profileid = getProfileId(req); + let postid = req.body.postid; + r = await DB.unbookmarkPost(postid, profileid); return res.json({ status: "ok" })