bookmarks in progress missing notifications

This commit is contained in:
Adolfo Reyna
2021-09-14 23:00:23 -07:00
parent 0907c1c1b5
commit 55c0c10a35
4 changed files with 53 additions and 5 deletions

View File

@@ -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) => { DB.newComment = (postid, comment) => {
const id = DB.ObjectID(postid); const id = DB.ObjectID(postid);
return DB.postCols.updateOne({_id: id}, { return DB.postCols.updateOne({_id: id}, {

View File

@@ -6,6 +6,7 @@ class Post {
this.createdAt = info.createdAt || new Date(); this.createdAt = info.createdAt || new Date();
this.reactions = info.reactions || {}; this.reactions = info.reactions || {};
this.comments = info.comments || []; this.comments = info.comments || [];
this.bookmarks = info.bookmarks || []; //set profiles subscribed to this post
//This should record edits //This should record edits
this.contentHistory = info.contentHistory || []; this.contentHistory = info.contentHistory || [];
this.toProfile = info.toProfile || ''; this.toProfile = info.toProfile || '';

View File

@@ -25,7 +25,11 @@ const Notifications = {
async youGotANewPostComment(postId, whoPostedId, message){ async youGotANewPostComment(postId, whoPostedId, message){
const DB = await DBGetter.getDB; const DB = await DBGetter.getDB;
const post = await DB.getPost(postId) const post = await DB.getPost(postId)
if(post.bookmarks){
//send notification to boorkmaked profiles
}
const profile = await DB.getProfileCache(post.profileid); 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 user = await DB.getUserById(profile.userid);
const senderProfile = await DB.getProfileCache(whoPostedId); const senderProfile = await DB.getProfileCache(whoPostedId);
let subject = senderProfile.profile.firstName + " comment on your post"; let subject = senderProfile.profile.firstName + " comment on your post";

View File

@@ -44,23 +44,40 @@ DB.getDB.then((DB)=>{
}); });
router.post("/react", async (req, res) => { router.post("/react", async (req, res) => {
let userid = getProfileId(req); let profileid = getProfileId(req);
let postid = req.body.postid; let postid = req.body.postid;
let reaction = { let reaction = {
type: "like", type: "like",
createdAt: new Date() createdAt: new Date()
}; };
r = await DB.newReaction(postid, userid, reaction); r = await DB.newReaction(postid, profileid, reaction);
return res.json({ return res.json({
status: "ok" status: "ok"
}); });
}) })
router.post("/unreact", async (req, res) => { router.post("/unreact", async (req, res) => {
let userid = getProfileId(req); let profileid = getProfileId(req);
let postid = req.body.postid; let postid = req.body.postid;
r = await DB.removeReaction(postid, userid); r = await DB.removeReaction(postid, profileid);
console.log(r) 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({ return res.json({
status: "ok" status: "ok"
}) })