Add promotional endpoint (extended) for new users

This commit is contained in:
Adolfo Reyna
2025-02-05 20:46:24 -05:00
parent bf2cdd4696
commit 309ae1b69b
2 changed files with 39 additions and 11 deletions

View File

@@ -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);