From e886b2bd577001318f63ea43e5d80ecd06134979 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Wed, 29 Sep 2021 13:51:16 -0700 Subject: [PATCH] fix feed to show group posts and filter private groups --- dbTools/post.js | 19 ++++++++++++++++--- dbTools/profile.js | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dbTools/post.js b/dbTools/post.js index c446baf..931f718 100644 --- a/dbTools/post.js +++ b/dbTools/post.js @@ -127,13 +127,26 @@ postDB = (DB)=>{ {profileid: { $in: ids }}, - //{toProfile: { - // $in: ids - //}} + {toProfile: { + $in: ids + }} ] }; return DB.postCols.find(query).sort({lastUpdated: -1}).limit(20).toArray().then(async (posts)=>{ //we need to filter when toProfile is private and not part of the following array + let filteredPosts = []; + for(p in posts){ + if(!DB.isGroupPrivate(p.profileid) && !DB.isGroupPrivate(p.toProfile)){ + filteredPosts.push(p); + } + if(DB.isGroupPrivate(p.profileid) && !profile[p.profileid]){ + continue; + } + if(DB.isGroupPrivate(p.toProfile) && !profile[p.toProfile]){ + continue; + } + filteredPosts.push(p); + } return posts; }).catch((err)=>{ console.log(err); diff --git a/dbTools/profile.js b/dbTools/profile.js index 71877b7..fd3e977 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -148,7 +148,7 @@ userDB = (DB) => { DB.isGroupPrivate = async (groupid) => { if(userProfileCache[groupid]) return userProfileCache[groupid].isPrivate; let g = await DB.getGroup(groupid); - return g.isPrivate; + return g ? g.isPrivate : false; } DB.getGroup = async (groupid) => {