feed with followers only

This commit is contained in:
Adolfo Reyna
2021-09-02 12:02:09 -07:00
parent fa0d6ee199
commit 9a302a87de
4 changed files with 70 additions and 2 deletions

View File

@@ -91,6 +91,27 @@ postDB = (DB)=>{
});
}
DB.getFeed = async (profileId) => {
const profile = await DB.getProfile(profileId);
let ids = profile.following.map((id)=>DB.ObjectID(id));
ids.push(profileId)
const _id = DB.ObjectID(profileId);
query = {
$or: [
{profileid: {
$in: ids
}},
{toProfile: {
$in: ids
}}
]
};
return DB.postCols.find(query).sort({_id: -1}).limit(20).toArray().catch((err)=>{
console.log(err);
return false;
});
}
DB.getPostsOfUser = (userId) => {
let userid = DB.ObjectID(userId);
return DB.postCols.find({userid}).sort({_id: -1}).toArray().catch((err)=>{

View File

@@ -45,6 +45,32 @@ userDB = (DB) => {
return r[index];
}
DB.followProfile = async (profileId, followProfileId)=>{
const _id = DB.ObjectID(profileId);
let update = {
$addToSet:{
following: followProfileId
}
}
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
console.log(err);
return false;
});
}
DB.unfollowProfile = async (profileId, followProfileId)=>{
const _id = DB.ObjectID(profileId);
let update = {
$pull:{
following: followProfileId
}
}
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
console.log(err);
return false;
});
}
//Groups
DB.getGroups = async () => {
let r = await DB.profileCols.find({isGroup: true})
@@ -75,6 +101,7 @@ userDB = (DB) => {
["subscribed." + profileid]: new Date()
}
}
DB.followProfile(profileid, groupid)
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
console.log(err);
return false;
@@ -88,6 +115,7 @@ userDB = (DB) => {
["subscribed." + profileid]: "",
}
}
DB.unfollowProfile(profileid, groupid)
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
console.log(err);
return false;