FIrst nonorganic posts
This commit is contained in:
@@ -48,6 +48,46 @@ userDB = (DB) => {
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.getPopularProfiles = async (limit = 10) => {
|
||||
return DB.profileCols.aggregate([
|
||||
{
|
||||
$match: {isGroup: false}
|
||||
},
|
||||
{
|
||||
$addFields: { subscribed_count: {$size: { "$ifNull": [ {"$objectToArray" : "$subscribed"}, [] ] } } }
|
||||
},
|
||||
{
|
||||
$sort: {"subscribed_count":-1}
|
||||
},
|
||||
{
|
||||
$project: {_id: 1, "subscribed_count": 1}
|
||||
}
|
||||
]).limit(limit).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getPopularGroups = async (limit = 10) => {
|
||||
return DB.profileCols.aggregate([
|
||||
{
|
||||
$match: {isGroup: true, isPrivate: false, isCourse: false}
|
||||
},
|
||||
{
|
||||
$addFields: { subscribed_count: {$size: { "$ifNull": [ {"$objectToArray" : "$subscribed"}, [] ] } } }
|
||||
},
|
||||
{
|
||||
$sort: {"subscribed_count":-1}
|
||||
},
|
||||
{
|
||||
$project: {_id: 1, "subscribed_count": 1}
|
||||
}
|
||||
]).limit(limit).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getProfileCache = async (profileId) => {
|
||||
if (userProfileCache[profileId] && !userProfileCache[profileId].isGroup) return userProfileCache[profileId];
|
||||
return DB.getProfile(profileId);
|
||||
|
||||
@@ -7,6 +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 should record edits
|
||||
this.contentHistory = info.contentHistory || [];
|
||||
this.toProfile = info.toProfile || '';
|
||||
@@ -38,6 +39,7 @@ class Post {
|
||||
r.createdAt = this.createdAt;
|
||||
r.reactions = this.reactions;
|
||||
r.comments = this.comments;
|
||||
r.nonOrganicType = this.nonOrganicType;
|
||||
r.contentHistory = this.contentHistory;
|
||||
r.lastUpdated = this.lastUpdated;
|
||||
r.toProfile = this.toProfile;
|
||||
|
||||
@@ -20,8 +20,21 @@ DB.getDB.then((DB) => {
|
||||
const profileid = getProfileId(req);
|
||||
let posts = await DB.getFeed(profileid);
|
||||
//Add non-organic posts
|
||||
|
||||
return res.json(posts)
|
||||
const popularProfiles = await DB.getPopularProfiles(5);
|
||||
let content = "Popular users to follow:\n";
|
||||
popularProfiles.forEach((p)=>{
|
||||
content += "@p:" + p._id + "\n";
|
||||
});
|
||||
let popularProfilesPost = new Post({profileid: 1, content, nonOrganicType: "PopularUsers"});
|
||||
const popularGroups = await DB.getPopularGroups(5);
|
||||
content = "Popular users to follow:\n";
|
||||
popularGroups.forEach((p)=>{
|
||||
content += "@p:" + p._id + "\n";
|
||||
});
|
||||
let popularGroupsPost = new Post({profileid: 1, content, nonOrganicType: "PopularGroups"});
|
||||
posts.push(popularProfilesPost);
|
||||
posts.push(popularGroupsPost);
|
||||
return res.json(posts);
|
||||
});
|
||||
|
||||
router.get("/usr/:id", async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user