subscribe to profiles

This commit is contained in:
Adolfo Reyna
2021-09-02 10:53:50 -07:00
parent ba2b0bcbd6
commit fa0d6ee199
5 changed files with 52 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ userDB = (DB) => {
}
DB.getProfile = async (profileId) => {
if (userProfileCache[profileId]) return userProfileCache[profileId];
//if (userProfileCache[profileId]) return userProfileCache[profileId];
const _id = DB.ObjectID(profileId);
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
console.log(err);
@@ -68,6 +68,31 @@ userDB = (DB) => {
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;
});
}
}