add private groups
This commit is contained in:
@@ -36,13 +36,7 @@ userDB = (DB) => {
|
||||
|
||||
DB.getProfileCache = async (profileId) => {
|
||||
if (userProfileCache[profileId] && !userProfileCache[profileId].isGroup) return userProfileCache[profileId];
|
||||
const _id = DB.ObjectID(profileId);
|
||||
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
if (r) userProfileCache[profileId] = r;
|
||||
return r;
|
||||
return DB.getProfile(profileId);
|
||||
}
|
||||
|
||||
DB.getProfiles = async (query) => {
|
||||
@@ -148,11 +142,17 @@ userDB = (DB) => {
|
||||
return r;
|
||||
}
|
||||
|
||||
let privateGroupsCache = {};
|
||||
DB.isGroupPrivate = async (groupid) => {
|
||||
if(userProfileCache[groupid]) return userProfileCache[groupid].isPrivate;
|
||||
let g = await DB.getGroup(groupid);
|
||||
return g.isPrivate;
|
||||
}
|
||||
|
||||
DB.getGroup = async (groupid) => {
|
||||
const _id = DB.ObjectID(groupid);
|
||||
//if(userProfileCache[groupid]) return userProfileCache[groupid];
|
||||
let r = await DB.profileCols.findOne({_id, isGroup: true})
|
||||
.toArray().catch((err) => {
|
||||
let r = await DB.profileCols.findOne({_id, isGroup: true}).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
@@ -160,15 +160,35 @@ userDB = (DB) => {
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.subscribeToGroup = async (profileid, groupid) => {
|
||||
DB.subscribeToGroup = async (profileid, groupid, reqSubscription = false) => {
|
||||
const _id = DB.ObjectID(groupid);
|
||||
const subOrRequest = reqSubscription ? "pending." : "subscribed.";
|
||||
let update = {
|
||||
$set:{
|
||||
[subOrRequest + profileid]: new Date()
|
||||
}
|
||||
}
|
||||
if(!reqSubscription) DB.followProfile(profileid, groupid);
|
||||
delete userProfileCache[groupid];
|
||||
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.acceptGroupJoinReq = async (profileid, groupid) => {
|
||||
const _id = DB.ObjectID(groupid);
|
||||
let update = {
|
||||
$set:{
|
||||
["subscribed." + profileid]: new Date()
|
||||
}
|
||||
},
|
||||
$unset:{
|
||||
["pending." + profileid]: ""
|
||||
}
|
||||
}
|
||||
DB.followProfile(profileid, groupid)
|
||||
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||
delete userProfileCache[groupid];
|
||||
return DB.profileCols.updateOne({_id}, update).then(console.log).catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user