feed with followers only
This commit is contained in:
@@ -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) => {
|
DB.getPostsOfUser = (userId) => {
|
||||||
let userid = DB.ObjectID(userId);
|
let userid = DB.ObjectID(userId);
|
||||||
return DB.postCols.find({userid}).sort({_id: -1}).toArray().catch((err)=>{
|
return DB.postCols.find({userid}).sort({_id: -1}).toArray().catch((err)=>{
|
||||||
|
|||||||
@@ -45,6 +45,32 @@ userDB = (DB) => {
|
|||||||
return r[index];
|
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
|
//Groups
|
||||||
DB.getGroups = async () => {
|
DB.getGroups = async () => {
|
||||||
let r = await DB.profileCols.find({isGroup: true})
|
let r = await DB.profileCols.find({isGroup: true})
|
||||||
@@ -75,6 +101,7 @@ userDB = (DB) => {
|
|||||||
["subscribed." + profileid]: new Date()
|
["subscribed." + profileid]: new Date()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DB.followProfile(profileid, groupid)
|
||||||
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return false;
|
||||||
@@ -88,6 +115,7 @@ userDB = (DB) => {
|
|||||||
["subscribed." + profileid]: "",
|
["subscribed." + profileid]: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DB.unfollowProfile(profileid, groupid)
|
||||||
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ DB.getDB.then((DB)=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
let posts = await DB.getPosts();
|
const profileid = getProfileId(req);
|
||||||
|
let posts = await DB.getFeed(profileid);
|
||||||
return res.json(posts)
|
return res.json(posts)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ DB.getDB.then((DB)=>{
|
|||||||
router.get("/groups/:id/unsubscribe", async (req, res) => {
|
router.get("/groups/:id/unsubscribe", async (req, res) => {
|
||||||
const groupid = req.params.id;
|
const groupid = req.params.id;
|
||||||
const profileid = getProfileId(req);
|
const profileid = getProfileId(req);
|
||||||
DB.unsubscribeToGroup(profileid, groupid).then(console.log);
|
DB.unsubscribeToGroup(profileid, groupid);
|
||||||
return res.json({
|
return res.json({
|
||||||
status: "ok"
|
status: "ok"
|
||||||
});
|
});
|
||||||
@@ -96,6 +96,24 @@ DB.getDB.then((DB)=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/:id/follow", async (req, res) => {
|
||||||
|
let followProfileId = req.params.id;
|
||||||
|
const profileid = getProfileId(req);
|
||||||
|
DB.followProfile(profileid, followProfileId);
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/:id/unfollow", async (req, res) => {
|
||||||
|
let followProfileId = req.params.id;
|
||||||
|
const profileid = getProfileId(req);
|
||||||
|
DB.unfollowProfile(profileid, followProfileId);
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
Reference in New Issue
Block a user