Subscriptions

This commit is contained in:
aeroreyna
2022-02-04 22:54:48 -06:00
parent cb056a078a
commit 294cacf963
4 changed files with 78 additions and 12 deletions

View File

@@ -5,9 +5,9 @@ const DB = require("./../mongoDB.js");
const Post = require("./../def/post.js");
const Notifications = require("./../notifications.js");
DB.getDB.then((DB)=>{
DB.getDB.then((DB) => {
const getProfileId = (req)=>{
const getProfileId = (req) => {
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
}
@@ -15,13 +15,22 @@ DB.getDB.then((DB)=>{
const profileid = getProfileId(req);
let posts = await DB.getFeed(profileid);
//Add non-organic posts
return res.json(posts)
});
router.get("/usr/:id", async (req, res) => {
const profileId = req.params.id;
const posts = await DB.getPosts(profileId, getProfileId(req));
const viewerProdileId = getProfileId(req);
const profile = await DB.getProfileCache(profileId);
const posts = await DB.getPosts(profileId, viewerProdileId);
if (profile.isCourse) {
//check for subscription
//const viewerProdile = await DB.getProfileCache(viewerProdileId);
//if (!viewerProdile.subscription || viewerProdile.subscription < (new Date()-1)) {
// return res.json([posts[posts.length - 1]]);
//}
}
return res.json(posts);
});
@@ -30,10 +39,10 @@ DB.getDB.then((DB)=>{
profileid: getProfileId(req),
...req.body
}
if(post.toProfile && await DB.isGroupPrivate(post.toProfile)){
if (post.toProfile && await DB.isGroupPrivate(post.toProfile)) {
let requestProfile = getProfileId(req) + "";
let group = await DB.getProfileCache(post.toProfile);
if(!group.subscribed[requestProfile] && group._id != requestProfile){
if (!group.subscribed[requestProfile] && group._id != requestProfile) {
return res.json({
status: "You are not part of this private group",
});
@@ -44,7 +53,7 @@ DB.getDB.then((DB)=>{
let dbr = await DB.newPost(postObj);
post = postObj.toObj();
post._id = dbr.insertedId;
if(post.toProfile && post.toProfile != post.profileid){
if (post.toProfile && post.toProfile != post.profileid) {
Notifications.youGotANewPost(post)
}
return res.json({
@@ -131,7 +140,7 @@ DB.getDB.then((DB)=>{
const post = await DB.getPost(postId);
return res.json({
status: "ok",
... post
...post
});
});