diff --git a/dbTools/post.js b/dbTools/post.js index e54546d..cb7849e 100644 --- a/dbTools/post.js +++ b/dbTools/post.js @@ -166,7 +166,8 @@ postDB = (DB)=>{ {toProfile: { $in: ids }} - ] + ], + nonOrganicType: null }; return DB.postCols.find(query).sort({lastUpdated: -1}).limit(20).toArray().then(async (posts)=>{ return await filterPrivateGroups(posts, profile); @@ -176,6 +177,16 @@ postDB = (DB)=>{ }); } + DB.getNews = async () => { + let query = { + nonOrganicType: 'News' + }; + return DB.postCols.find(query).sort({lastUpdated: -1}).limit(20).toArray().catch((err)=>{ + console.log(err); + return []; + }); + } + DB.getPostsOfUser = (userId) => { let userid = DB.ObjectID(userId); console.log("getPostsOfUser") diff --git a/def/post.js b/def/post.js index 6ec6c41..1597c08 100644 --- a/def/post.js +++ b/def/post.js @@ -7,7 +7,7 @@ class Post { this.reactions = info.reactions || {}; this.comments = info.comments || []; this.bookmarks = info.bookmarks || []; //set profiles subscribed to this post - this.nonOrganicType = info.nonOrganicType; + this.nonOrganicType = info.nonOrganicType; //change this to inorganic //This should record edits this.contentHistory = info.contentHistory || []; this.toProfile = info.toProfile || ''; diff --git a/routes/post.js b/routes/post.js index 8647439..2484ba6 100644 --- a/routes/post.js +++ b/routes/post.js @@ -18,9 +18,13 @@ DB.getDB.then((DB) => { const generateNonOrganicPosts = async (req, profileid) => { let posts = []; + // News Posts + const newsPosts = await DB.getNews(); + posts.push(...newsPosts); + // Popular Profiles const popularProfiles = await DB.getPopularProfiles(5); - let content = "Active users to follow:\n"; + content = "Active users to follow:\n"; popularProfiles.forEach((p)=>{ content += "@p:" + p._id + "\n"; }); @@ -60,6 +64,10 @@ DB.getDB.then((DB) => { mergedPosts.push(organic.shift()); continue; } + if(nonOrganic[0].nonOrganicType == 'News'){ + mergedPosts.push(nonOrganic.shift()); + continue; + } if(Math.random() < 0.2){ mergedPosts.push(nonOrganic.shift()); } else { @@ -132,7 +140,7 @@ DB.getDB.then((DB) => { return res.json({ status: "ok" }); - }) + }); router.post("/unreact", async (req, res) => { let profileid = getProfileId(req);