subscribe to profiles
This commit is contained in:
@@ -29,9 +29,7 @@ postDB = (DB)=>{
|
|||||||
const id = DB.ObjectID(postid);
|
const id = DB.ObjectID(postid);
|
||||||
let update = {
|
let update = {
|
||||||
$unset:{
|
$unset:{
|
||||||
reactions:{
|
["reactions." + profileid]: ""
|
||||||
[userid]: {}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
$set: {
|
$set: {
|
||||||
lastUpdated: new Date()
|
lastUpdated: new Date()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ userDB = (DB) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DB.getProfile = async (profileId) => {
|
DB.getProfile = async (profileId) => {
|
||||||
if (userProfileCache[profileId]) return userProfileCache[profileId];
|
//if (userProfileCache[profileId]) return userProfileCache[profileId];
|
||||||
const _id = DB.ObjectID(profileId);
|
const _id = DB.ObjectID(profileId);
|
||||||
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
|
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -68,6 +68,31 @@ userDB = (DB) => {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB.subscribeToGroup = async (profileid, groupid) => {
|
||||||
|
const _id = DB.ObjectID(groupid);
|
||||||
|
let update = {
|
||||||
|
$set:{
|
||||||
|
["subscribed." + profileid]: new Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
DB.unsubscribeToGroup = async (profileid, groupid) => {
|
||||||
|
const _id = DB.ObjectID(groupid);
|
||||||
|
let update = {
|
||||||
|
$unset:{
|
||||||
|
["subscribed." + profileid]: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class User {
|
|||||||
this.newsFeedCache = info.newsFeedCache || [];
|
this.newsFeedCache = info.newsFeedCache || [];
|
||||||
this.isGroup = info.isGroup || false;
|
this.isGroup = info.isGroup || false;
|
||||||
this.isCourse = info.isCourse || false;
|
this.isCourse = info.isCourse || false;
|
||||||
|
this.subscribed = info.subscribed || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
toObj(){
|
toObj(){
|
||||||
@@ -32,6 +33,7 @@ class User {
|
|||||||
r.newsFeedCache = this.newsFeedCache;
|
r.newsFeedCache = this.newsFeedCache;
|
||||||
r.isGroup = this.isGroup;
|
r.isGroup = this.isGroup;
|
||||||
r.isCourse = this.isCourse;
|
r.isCourse = this.isCourse;
|
||||||
|
r.subscribed = this.subscribed;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const Post = require("./../def/post.js");
|
|||||||
DB.getDB.then((DB)=>{
|
DB.getDB.then((DB)=>{
|
||||||
|
|
||||||
const getProfileId = (req)=>{
|
const getProfileId = (req)=>{
|
||||||
return DB.ObjectID(req.cookies.profile_id);
|
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ DB.getDB.then((DB)=>{
|
|||||||
return DB.ObjectID(user_sid);
|
return DB.ObjectID(user_sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getProfileId = (req)=>{
|
||||||
|
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
|
||||||
|
}
|
||||||
|
|
||||||
router.get("/mine", async (req, res) => {
|
router.get("/mine", async (req, res) => {
|
||||||
let userid = req.cookies.user_sid;
|
let userid = req.cookies.user_sid;
|
||||||
let profiles = await DB.getUserProfiles(userid);
|
let profiles = await DB.getUserProfiles(userid);
|
||||||
@@ -65,6 +69,24 @@ DB.getDB.then((DB)=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/groups/:id/subscribe", async (req, res) => {
|
||||||
|
const groupid = req.params.id;
|
||||||
|
const profileid = getProfileId(req);
|
||||||
|
DB.subscribeToGroup(profileid, groupid);
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/groups/:id/unsubscribe", async (req, res) => {
|
||||||
|
const groupid = req.params.id;
|
||||||
|
const profileid = getProfileId(req);
|
||||||
|
DB.unsubscribeToGroup(profileid, groupid).then(console.log);
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/:id", async (req, res) => {
|
router.get("/:id", async (req, res) => {
|
||||||
let profileId = req.params.id;
|
let profileId = req.params.id;
|
||||||
let profile = await DB.getProfile(profileId);
|
let profile = await DB.getProfile(profileId);
|
||||||
|
|||||||
Reference in New Issue
Block a user