Add promotional endpoint (extended) for new users
This commit is contained in:
@@ -176,29 +176,33 @@ postDB = (DB)=>{
|
||||
});
|
||||
}
|
||||
|
||||
// Filter out posts that are posted by private groups that the viewer is not part of.
|
||||
filterPrivateGroups = async (posts, profile) =>{
|
||||
let filteredPosts = [];
|
||||
let validatedPosts = [];
|
||||
let following = {};
|
||||
profile.following.forEach(element => {
|
||||
following[element] = 1;
|
||||
});
|
||||
for(i in posts){
|
||||
let p = posts[i];
|
||||
let isPostingAPrivateGroup = await DB.isGroupPrivate(p.profileid);
|
||||
let isPostingToAPrivateGroup = p.toProfile ? await DB.isGroupPrivate(p.toProfile) : false;
|
||||
if(!isPostingAPrivateGroup && !isPostingToAPrivateGroup){
|
||||
filteredPosts.push(p);
|
||||
let isPostedByAPrivateGroup = await DB.isGroupPrivate(p.profileid);
|
||||
let isPostedToAPrivateGroup = p.toProfile ? await DB.isGroupPrivate(p.toProfile) : false;
|
||||
// Not private posts
|
||||
if(!isPostedByAPrivateGroup && !isPostedToAPrivateGroup){
|
||||
validatedPosts.push(p);
|
||||
continue;
|
||||
}
|
||||
if(isPostingAPrivateGroup && !following[p.profileid]){
|
||||
// skipps private post if viewer is not part of the group
|
||||
if(isPostedByAPrivateGroup && !following[p.profileid]){
|
||||
continue;
|
||||
}
|
||||
if(isPostingToAPrivateGroup && !following[p.toProfile]){
|
||||
if(isPostedToAPrivateGroup && !following[p.toProfile]){
|
||||
continue;
|
||||
}
|
||||
filteredPosts.push(p);
|
||||
// Private but the user is part of the group
|
||||
validatedPosts.push(p);
|
||||
}
|
||||
return filteredPosts;
|
||||
return validatedPosts;
|
||||
}
|
||||
|
||||
DB.getFeed = async (profileId) => {
|
||||
@@ -217,7 +221,22 @@ postDB = (DB)=>{
|
||||
],
|
||||
nonOrganicType: null // Exlcude news
|
||||
};
|
||||
return DB.postCols.find(query).sort({lastUpdated: -1}).limit(20).toArray().then(async (posts)=>{
|
||||
return DB.postCols.find(query).sort({lastUpdated: -1}).limit(30).toArray().then(async (posts)=>{
|
||||
return await filterPrivateGroups(posts, profile);
|
||||
}).catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getPromotionalPosts = async (profileId) => {
|
||||
if(!DB.ObjectID.isValid(profileId)) return [];
|
||||
const profile = await DB.getProfile(profileId);
|
||||
if(!profile) return [];
|
||||
query = {
|
||||
nonOrganicType: null // Exlcude news
|
||||
};
|
||||
return DB.postCols.find(query).sort({lastUpdated: -1}).limit(50).toArray().then(async (posts)=>{
|
||||
return await filterPrivateGroups(posts, profile);
|
||||
}).catch((err)=>{
|
||||
console.log(err);
|
||||
|
||||
@@ -82,7 +82,16 @@ DB.getDB.then((DB) => {
|
||||
let organicPosts = await DB.getFeed(profileid);
|
||||
//Add non-organic posts
|
||||
const nonOrganicPosts = await generateNonOrganicPosts(req, profileid);
|
||||
const posts = mergePosts(organicPosts, nonOrganicPosts);
|
||||
const posts = mergePosts(promotionalPosts, nonOrganicPosts);
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
router.get("/extended", async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
//Add non-organic posts
|
||||
const nonOrganicPosts = await generateNonOrganicPosts(req, profileid);
|
||||
let promotionalPosts = await DB.getPromotionalPosts(profileid);
|
||||
const posts = mergePosts(promotionalPosts, nonOrganicPosts);
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user