fix private groups visibility on feed and profiles
This commit is contained in:
@@ -100,8 +100,8 @@ postDB = (DB)=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.getPosts = async (profileId) => {
|
DB.getPosts = async (profileId, viewerProfileId) => {
|
||||||
const profile = await DB.getProfile(profileId);
|
const profile = await DB.getProfile(viewerProfileId);
|
||||||
let query = {};
|
let query = {};
|
||||||
if(profileId) {
|
if(profileId) {
|
||||||
const id = DB.ObjectID(profileId);
|
const id = DB.ObjectID(profileId);
|
||||||
@@ -122,18 +122,24 @@ postDB = (DB)=>{
|
|||||||
|
|
||||||
filterPrivateGroups = async (posts, profile) =>{
|
filterPrivateGroups = async (posts, profile) =>{
|
||||||
let filteredPosts = [];
|
let filteredPosts = [];
|
||||||
|
let following = {};
|
||||||
|
profile.following.forEach(element => {
|
||||||
|
following[element] = 1;
|
||||||
|
});
|
||||||
|
console.log(following)
|
||||||
for(i in posts){
|
for(i in posts){
|
||||||
let p = posts[i];
|
let p = posts[i];
|
||||||
let isPostingAPrivateGroup = await DB.isGroupPrivate(p.profileid);
|
let isPostingAPrivateGroup = await DB.isGroupPrivate(p.profileid);
|
||||||
let isPostingToAPrivateGroup = p.toProfile ? await DB.isGroupPrivate(p.toProfile) : false;
|
let isPostingToAPrivateGroup = p.toProfile ? await DB.isGroupPrivate(p.toProfile) : false;
|
||||||
|
console.log(following[p.profileid], following[p.toProfile + ""], p.toProfile)
|
||||||
if(!isPostingAPrivateGroup && !isPostingToAPrivateGroup){
|
if(!isPostingAPrivateGroup && !isPostingToAPrivateGroup){
|
||||||
filteredPosts.push(p);
|
filteredPosts.push(p);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(isPostingAPrivateGroup && !profile[p.profileid]){
|
if(isPostingAPrivateGroup && !following[p.profileid + ""]){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(isPostingToAPrivateGroup && !profile[p.toProfile]){
|
if(isPostingToAPrivateGroup && !following[p.toProfile + ""]){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
filteredPosts.push(p);
|
filteredPosts.push(p);
|
||||||
@@ -144,8 +150,7 @@ postDB = (DB)=>{
|
|||||||
DB.getFeed = async (profileId) => {
|
DB.getFeed = async (profileId) => {
|
||||||
const profile = await DB.getProfile(profileId);
|
const profile = await DB.getProfile(profileId);
|
||||||
let ids = profile.following.map((id)=>DB.ObjectID(id));
|
let ids = profile.following.map((id)=>DB.ObjectID(id));
|
||||||
ids.push(profileId)
|
ids.push(DB.ObjectID(profileId))
|
||||||
const _id = DB.ObjectID(profileId);
|
|
||||||
query = {
|
query = {
|
||||||
$or: [
|
$or: [
|
||||||
{profileid: {
|
{profileid: {
|
||||||
|
|||||||
@@ -21,14 +21,7 @@ DB.getDB.then((DB)=>{
|
|||||||
|
|
||||||
router.get("/usr/:id", async (req, res) => {
|
router.get("/usr/:id", async (req, res) => {
|
||||||
const profileId = req.params.id;
|
const profileId = req.params.id;
|
||||||
if(await DB.isGroupPrivate(profileId)){
|
const posts = await DB.getPosts(profileId, getProfileId(req));
|
||||||
let requestProfile = getProfileId(req) + "";
|
|
||||||
let group = await DB.getProfileCache(profileId);
|
|
||||||
if(!group.subscribed[requestProfile] && profileId != requestProfile){
|
|
||||||
return res.json([]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const posts = await DB.getPosts(profileId);
|
|
||||||
return res.json(posts);
|
return res.json(posts);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user