From af059b6fc6f5b31b747652220c2221605d2ea726 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Tue, 7 Feb 2023 13:40:18 -0500 Subject: [PATCH 1/3] restric newsOnly groups from posting --- dbTools/profile.js | 6 ++++++ routes/post.js | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dbTools/profile.js b/dbTools/profile.js index f4f3240..106862c 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -352,6 +352,12 @@ userDB = (DB) => { return g ? g.isPrivate : false; } + DB.isGroupNewsOnly = async (groupid) => { + if(userProfileCache[groupid]) return userProfileCache[groupid].newsOnly; + let g = await DB.getGroup(groupid); + return g ? g.newsOnly : false; + } + DB.isOwnerOfGroup = async (profileid, groupid) => { let profile = await DB.getProfileCache(profileid); let group = userProfileCache[groupid] ? userProfileCache[groupid] : await DB.getGroup(groupid); diff --git a/routes/post.js b/routes/post.js index 262fbda..6ee4e83 100644 --- a/routes/post.js +++ b/routes/post.js @@ -141,7 +141,9 @@ DB.getDB.then((DB) => { profileid: getProfileId(req), ...req.body } - if (post.toProfile && await DB.isGroupPrivate(post.toProfile)) { + const isGroupPrivate = await DB.isGroupPrivate(post.toProfile); + const isGroupNewsOnly = await DB.isGroupNewsOnly(post.toProfile); + if (post.toProfile && isGroupPrivate) { let requestProfile = getProfileId(req) + ""; let group = await DB.getProfileCache(post.toProfile); if (!group.subscribed[requestProfile] && group._id != requestProfile) { @@ -150,6 +152,11 @@ DB.getDB.then((DB) => { }); } } + if (post.toProfile && isGroupNewsOnly) { + return res.json({ + status: "This is a news only group, only the admin can post", + }); + } post.toProfile = post.toProfile ? DB.ObjectID(post.toProfile) : undefined; let postObj = new Post(post); let dbr = await DB.newPost(postObj); From 7ff9223a5ccd6f0827643f59b0bdc86667632976 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Tue, 7 Feb 2023 15:51:37 -0500 Subject: [PATCH 2/3] Notifs for groups posting in feed --- notifications.js | 14 ++++++++++++++ routes/post.js | 1 + 2 files changed, 15 insertions(+) diff --git a/notifications.js b/notifications.js index fffcbbe..3f07c08 100644 --- a/notifications.js +++ b/notifications.js @@ -395,6 +395,11 @@ 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 + if(groupProfile._id == senderProfile._id){ + const notifBody = `${groupProfile.profile.firstName} ${groupProfile.profile.lastName} has a new post!`; + sendPushNotification(userProfile.token, notifBody, {}); + return DB.addNotification(userProfile._id, notifBody, post._id, null, senderProfile._id); + } 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, null, senderProfile._id); @@ -422,6 +427,15 @@ const Notifications = { DB.addNotification(toProfileId, notifBody, post._id, null, senderProfile._id); return youGotANewPostTemplate(profile, user.username, senderProfile, message); }, + async yourGroupMakeANewPost(post) { + const whoPostedId = post.profileid; + const message = post.content; + const DB = await DBGetter.getDB; + const profile = await DB.getProfileCache(whoPostedId); + if (profile.isGroup) { + return this.yourGroupGotANewPost(profile, profile, message, post); + } + }, youHaveAnInvitation, broadcastNews, async yourGroupHasARequest(requesterProfileId, groupId) { diff --git a/routes/post.js b/routes/post.js index 6ee4e83..617e57a 100644 --- a/routes/post.js +++ b/routes/post.js @@ -165,6 +165,7 @@ DB.getDB.then((DB) => { if ((post.toProfile && post.toProfile != post.profileid) || post.nonOrganicType == 'News') { Notifications.youGotANewPost(post); } + Notifications.yourGroupGotANewPost(post); return res.json({ status: "ok", ...post From 4448521fdb2a5fea6ae9444624cdabca440640cc Mon Sep 17 00:00:00 2001 From: aeroreyna Date: Wed, 8 Feb 2023 20:00:05 -0500 Subject: [PATCH 3/3] fix minor bug --- notifications.js | 1 + 1 file changed, 1 insertion(+) diff --git a/notifications.js b/notifications.js index 3f07c08..3628dbf 100644 --- a/notifications.js +++ b/notifications.js @@ -384,6 +384,7 @@ const Notifications = { }, async yourGroupGotANewPost(groupProfile, senderProfile, message, post) { const DB = await DBGetter.getDB; + if(!groupProfile.subscribed) return 0; let subscribedPromise = Object.keys(groupProfile.subscribed).map((profileid) => { return DB.getProfileCache(profileid); });