- Accepted and Refused Group Entering
- Report a User
This commit is contained in:
@@ -171,6 +171,7 @@ MyBachecaSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -264,6 +265,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -320,6 +322,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -376,6 +379,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
/*{
|
||||
@@ -432,6 +436,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -488,6 +493,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -171,6 +171,7 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -263,6 +264,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -318,6 +320,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -373,6 +376,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -428,6 +432,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -483,6 +488,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -71,6 +71,9 @@ const MyGroupSchema = new Schema({
|
||||
pwd_cryp: {
|
||||
type: String,
|
||||
},
|
||||
createdBy: {
|
||||
type: String,
|
||||
},
|
||||
admins: [
|
||||
{
|
||||
username: {type: String},
|
||||
|
||||
@@ -171,6 +171,7 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -259,6 +260,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -310,6 +312,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -361,6 +364,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
/*{
|
||||
@@ -412,6 +416,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -463,6 +468,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -172,6 +172,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -263,6 +264,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -317,6 +319,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -371,6 +374,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
/*{
|
||||
@@ -427,6 +431,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -481,6 +486,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -55,6 +55,9 @@ const sendNotifSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
options: {
|
||||
type: Number,
|
||||
},
|
||||
read: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -69,6 +72,9 @@ const sendNotifSchema = new Schema({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
extrafield: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
@@ -126,6 +132,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
let mydescr = '';
|
||||
let myidrec = '';
|
||||
let userorig = recnotif.sender;
|
||||
let tag = '';
|
||||
|
||||
try {
|
||||
if (recnotif.myrectableorig) {
|
||||
@@ -150,16 +157,56 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
|
||||
newdescr = i18n.__('<strong>%s</strong> refused your Friendship', userorig, mydescr);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REPORTED) {
|
||||
if (recnotif.paramsObj.usernameDest === recnotif.paramsObj.username_action) {
|
||||
newdescr = i18n.__('FRIEND_REPORTED_YOU', recnotif.paramsObj.username_worked);
|
||||
} else if (recnotif.paramsObj.isAdmin) {
|
||||
newdescr = i18n.__('FRIEND_REPORTED', recnotif.paramsObj.usernameDest, userorig);
|
||||
} else {
|
||||
newdescr = i18n.__('FRIEND_REPORTED_TO_ME', recnotif.paramsObj.username_action, recnotif.paramsObj.username_action);
|
||||
}
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
recnotif.openUrl = '/grp/' + recnotif.paramsObj.groupNameDest;
|
||||
recnotif.openUrl = '/grp/' + recnotif.paramsObj.groupnameDest;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
|
||||
newdescr = i18n.__('GROUP_CREATED', userorig, recnotif.paramsObj.groupNameDest);
|
||||
newdescr = i18n.__('GROUP_CREATED', userorig, recnotif.paramsObj.groupnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
newdescr = i18n.__('GROUPS_ACCEPTED', userorig, recnotif.paramsObj.groupNameDest);
|
||||
if (recnotif.paramsObj.isAdmin)
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
else
|
||||
newdescr = i18n.__('GROUPS_ACCEPTED', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
tag = 'addgroup';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REMOVED) {
|
||||
if (recnotif.paramsObj.username_action === recnotif.paramsObj.usernameDest && userorig === recnotif.paramsObj.usernameDest)
|
||||
newdescr = i18n.__('GROUPS_EXIT_USER_TO_ME', recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
else if (userorig === recnotif.paramsObj.usernameDest)
|
||||
newdescr = i18n.__('GROUPS_REMOVED_TO_ME', recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
else if (userorig === recnotif.paramsObj.username_action)
|
||||
newdescr = i18n.__('GROUPS_EXIT_USER', userorig, recnotif.paramsObj.groupnameDest);
|
||||
else
|
||||
newdescr = i18n.__('GROUPS_REMOVED', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
tag = 'remgroup';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REFUSED) {
|
||||
newdescr = i18n.__('GROUPS_REFUSED', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
tag = 'addgroup';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER) {
|
||||
newdescr = i18n.__('GROUP_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.singleadmin_username);
|
||||
tag = 'reqgroups';
|
||||
// sendnotifPush = false; // non lo rimandare 2 volte !
|
||||
// telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_GRUPPO, myuser, singleadmin.username, groupname, group._id);
|
||||
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_BLOCK_USER) {
|
||||
newdescr = i18n.__('RICHIESTA_BLOCCO_GRUPPO', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.singleadmin_username);
|
||||
tag = 'blockgroups';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_DELETE_USER) {
|
||||
newdescr = i18n.__('GRUPPO_ELIMINATO', userorig, recnotif.paramsObj.username_action);
|
||||
tag = 'deletegroup';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
recnotif.tag = recnotif.tag ? recnotif.tag : tag;
|
||||
|
||||
if (!recnotif.descr) {
|
||||
recnotif.descr = newdescr;
|
||||
}
|
||||
@@ -216,95 +263,139 @@ sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function(username, idap
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.saveAndSendNotif = function(myrecnotif, req, res, user) {
|
||||
sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res, user) {
|
||||
const SendNotif = this;
|
||||
|
||||
let idapp = req.body.idapp;
|
||||
const check = tools.checkUserOk(myrecnotif.sender, user ? myrecnotif.sender : req.user.username, res);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
myrecnotif._id = new ObjectID();
|
||||
if (!myrecnotif.openUrl) {
|
||||
// If not exist, then I set openUrl and description
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, false);
|
||||
if (!myrecout)
|
||||
return null;
|
||||
|
||||
if (save) {
|
||||
await myrecout.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
|
||||
return SendNotif.findById(idobj).lean().then(async (recnotif) => {
|
||||
return await globalTables.sendNotif(myrecnotif.typedir, myrecnotif.typeid, res, idapp, user ? user : req.user, recnotif).
|
||||
then((ris) => {
|
||||
return recnotif;
|
||||
});
|
||||
});
|
||||
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
return await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout).
|
||||
then((ris) => {
|
||||
return myrecout;
|
||||
});
|
||||
}
|
||||
|
||||
return myrecnotif.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
};
|
||||
|
||||
myrecnotif._id = idobj;
|
||||
sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysave) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
if (!myrecnotif.openUrl) {
|
||||
// If not exist, then I set openUrl and description
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
}
|
||||
|
||||
let newstatus = 0;
|
||||
let typeidsearch = 0;
|
||||
let dest = '';
|
||||
|
||||
// Controllare se devo modificare un Notif già esistente !
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_ACCEPTED;
|
||||
dest = myrecnotif.sender;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_REFUSED;
|
||||
dest = myrecnotif.sender;
|
||||
}
|
||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_ACCEPTED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REFUSED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_REFUSED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REMOVED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_REMOVED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_BLOCK_USER) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_BLOCKED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_DELETE_USER) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_DELETED;
|
||||
dest = myrecnotif.dest;
|
||||
}
|
||||
}
|
||||
|
||||
if (newstatus) {
|
||||
const fields_to_update = {
|
||||
status: newstatus,
|
||||
read: true,
|
||||
descr: myrecnotif.descr,
|
||||
};
|
||||
|
||||
const query = {
|
||||
idapp: myrecnotif.idapp,
|
||||
typedir: myrecnotif.typedir,
|
||||
typeid: typeidsearch,
|
||||
dest,
|
||||
deleted: false,
|
||||
status: 0,
|
||||
};
|
||||
|
||||
// Cerca il record e se lo trova lo aggiorna
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
|
||||
new: true,
|
||||
returnNewDocument: true,
|
||||
});
|
||||
|
||||
if (myrec) {
|
||||
return {myrecout: myrec, save: false};
|
||||
}
|
||||
}
|
||||
|
||||
myrecnotif._id = new ObjectID();
|
||||
if (newstatus > 0) {
|
||||
myrecnotif.status = newstatus;
|
||||
}
|
||||
|
||||
return {myrecout: myrecnotif, save: true};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {myrecout: null, save: false};
|
||||
}
|
||||
|
||||
return SendNotif.findById(idobj).lean().then(async (recnotif) => {
|
||||
return await globalTables.sendNotif(myrecnotif.typedir, myrecnotif.typeid, res, idapp, user ? user : req.user, recnotif).
|
||||
then((ris) => {
|
||||
return recnotif;
|
||||
});
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
|
||||
|
||||
const SendNotif = this;
|
||||
|
||||
let newstatus = 0;
|
||||
let typeidsearch = 0;
|
||||
// Controllare se devo modificare un Notif già esistente !
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_ACCEPTED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_REFUSED;
|
||||
}
|
||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_GROUPS_ACCEPTED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REFUSED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_GROUPS_REFUSED;
|
||||
}
|
||||
}
|
||||
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, true);
|
||||
if (!myrecout)
|
||||
return null;
|
||||
|
||||
if (newstatus) {
|
||||
const fields_to_update = {
|
||||
status: newstatus,
|
||||
read: true,
|
||||
};
|
||||
|
||||
const query = {
|
||||
idapp: myrecnotif.idapp,
|
||||
typedir: myrecnotif.typedir,
|
||||
typeid: typeidsearch,
|
||||
dest: myrecnotif.sender,
|
||||
deleted: false,
|
||||
status: 0,
|
||||
};
|
||||
|
||||
// Cerca il record e se lo trova lo aggiorna
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
|
||||
new: false,
|
||||
returnNewDocument: true,
|
||||
});
|
||||
|
||||
if (myrec) {
|
||||
return myrec._doc;
|
||||
}
|
||||
}
|
||||
|
||||
myrecnotif._id = new ObjectID();
|
||||
if (!myrecnotif.openUrl) {
|
||||
// If not exist, then I set openUrl and description
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
}
|
||||
|
||||
return myrecnotif.save().then((writeresult) => {
|
||||
return myrecout.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
|
||||
myrecnotif._id = idobj;
|
||||
|
||||
return SendNotif.findById(idobj).lean().then(async (recnotif) => {
|
||||
return recnotif;
|
||||
});
|
||||
@@ -334,11 +425,24 @@ sendNotifSchema.statics.getDefaultRec = function(req) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getExtraParam = function(myrecnotif, paramsObj) {
|
||||
let out = myrecnotif;
|
||||
//if (myrecnotif._doc) {
|
||||
//out = myrecnotif._doc
|
||||
//}
|
||||
out.paramsObj = paramsObj;
|
||||
out.options = paramsObj.options ? paramsObj.options : 0;
|
||||
out.extrafield = paramsObj.groupnameDest ? paramsObj.groupnameDest : '';
|
||||
|
||||
return myrecnotif;
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.createNewNotification = async function(req, res, paramsObj, table, rec, typedir, typeid) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
let myrecnotif = new SendNotif(this.getDefaultRec(req));
|
||||
myrecnotif = this.getExtraParam(myrecnotif, paramsObj);
|
||||
|
||||
myrecnotif.tablerec = table;
|
||||
if (rec && table) {
|
||||
@@ -348,7 +452,7 @@ sendNotifSchema.statics.createNewNotification = async function(req, res, paramsO
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
await SendNotif.sendToTheDestinations(myrecnotif, req, res, paramsObj);
|
||||
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -362,11 +466,12 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
|
||||
|
||||
try {
|
||||
let myrecnotif = new SendNotif(this.getDefaultRec(req));
|
||||
myrecnotif = this.getExtraParam(myrecnotif, paramsObj);
|
||||
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, paramsObj, onlysave);
|
||||
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, onlysave);
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -375,7 +480,7 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res, paramsObj) {
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res) {
|
||||
const SendNotif = this;
|
||||
|
||||
const {User} = require('../models/user');
|
||||
@@ -383,8 +488,6 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
const {City} = require('../models/city');
|
||||
const {Province} = require('../models/province');
|
||||
|
||||
myrecnotif.paramsObj = paramsObj;
|
||||
|
||||
try {
|
||||
|
||||
// Send only to the destination to reach:
|
||||
@@ -469,12 +572,12 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
||||
if (tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (send) {
|
||||
if (send) {
|
||||
myrecnotif.dest = user.username;
|
||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||
}
|
||||
@@ -487,19 +590,18 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, res, paramsObj, onlysave) {
|
||||
sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, res, onlysave) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
|
||||
myrecnotif.paramsObj = paramsObj;
|
||||
myrecnotif.dest = paramsObj.usernameDest ? paramsObj.usernameDest : '';
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
myrecnotif.dest = myrecnotif.paramsObj && myrecnotif.paramsObj.usernameDest ? myrecnotif.paramsObj.usernameDest : '';
|
||||
myrecnotif.username_worked = myrecnotif.paramsObj && myrecnotif.paramsObj.username_worked ? myrecnotif.paramsObj.username_worked : myrecnotif.dest;
|
||||
|
||||
if (onlysave) {
|
||||
await SendNotif.saveNotif(myrecnotif);
|
||||
} else {
|
||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, null);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -181,6 +181,15 @@ const UserSchema = new mongoose.Schema({
|
||||
date_blocked: {
|
||||
type: Date,
|
||||
},
|
||||
reported: {
|
||||
type: Boolean,
|
||||
},
|
||||
username_who_report: {
|
||||
type: String,
|
||||
},
|
||||
date_report: {
|
||||
type: Date,
|
||||
},
|
||||
non_voglio_imbarcarmi: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -386,7 +395,7 @@ const UserSchema = new mongoose.Schema({
|
||||
notif_sector_goods: [
|
||||
{
|
||||
type: Number,
|
||||
}]
|
||||
}],
|
||||
},
|
||||
})
|
||||
;
|
||||
@@ -693,6 +702,7 @@ UserSchema.statics.getUserShortDataByUsername = async function(idapp, username)
|
||||
name: 1,
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
reported: 1,
|
||||
sospeso: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
@@ -1355,6 +1365,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
username: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
date_reg: 1,
|
||||
@@ -1372,6 +1383,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.nationality': 1,
|
||||
@@ -1405,6 +1417,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
notask_verif: 1,
|
||||
@@ -1559,19 +1572,26 @@ UserSchema.statics.removeReqFriend = async function(
|
||||
{$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}});
|
||||
};
|
||||
|
||||
UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameDest, cmd, value) {
|
||||
UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, usernameDest, cmd, value) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
if (!req) {
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
}
|
||||
|
||||
const username_action = req.user.username;
|
||||
let username_worked = usernameDest;
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
if (cmd === shared_consts.FRIENDSCMD.SETTRUST) {
|
||||
|
||||
// Aggiungi alle amicizie
|
||||
await this.setFriendsCmd(idapp, usernameOrig, usernameDest,
|
||||
await this.setFriendsCmd(req, idapp, usernameOrig, usernameDest,
|
||||
shared_consts.FRIENDSCMD.SETFRIEND, value);
|
||||
|
||||
return User.updateOne({idapp, username: usernameDest},
|
||||
@@ -1601,11 +1621,13 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
// Send a notification to the DESTINATION FRIENDSHIP !
|
||||
let req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED);
|
||||
|
||||
// Send a notification to the SENDER FRIENDSHIP !
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
|
||||
|
||||
update = {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
@@ -1614,12 +1636,12 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
try {
|
||||
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
|
||||
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
|
||||
const msgOrig = i18n.__({phrase: '✅ %s accepted your Friendship request !', locale: user.lang}, usernameOrig)
|
||||
const msgDest = i18n.__({phrase: "✅ You have accepted %s' Friendship request!", locale: userDest.lang}, usernameDest);
|
||||
const msgOrig = i18n.__({phrase: '✅ %s accepted your Friendship request !', locale: user.lang}, usernameOrig);
|
||||
const msgDest = i18n.__({phrase: '✅ You have accepted %s\' Friendship request!', locale: userDest.lang}, usernameDest);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
@@ -1701,7 +1723,8 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_REFUSED);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REFUSED);
|
||||
|
||||
await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
ris = await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me
|
||||
@@ -1723,6 +1746,38 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
date_blocked: new Date(),
|
||||
},
|
||||
});
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REPORT_USER) {
|
||||
|
||||
username_worked = usernameDest;
|
||||
|
||||
// Segnalo la persona
|
||||
ris = await User.updateOne({idapp, username: username_worked}, {
|
||||
$set: {
|
||||
reported: true,
|
||||
username_who_report: usernameOrig,
|
||||
date_report: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
if (ris) {
|
||||
// Send a notification to the DESTINATION!
|
||||
// Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||
|
||||
// Send a notification to the SENDER !
|
||||
// Hai segnalato %s da %s per comportamenti non idonei.
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||
|
||||
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
|
||||
// Send a notification to the Admin
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
|
||||
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error: ', e);
|
||||
@@ -1744,9 +1799,19 @@ UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupn
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
// Controllo se è stato già inserito
|
||||
return User.countDocuments({
|
||||
idapp,
|
||||
'profile.mygroups': {
|
||||
$elemMatch: {groupname: {$eq: groupnameDest}},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
@@ -1765,11 +1830,6 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
SendNotif.createNewNotifToSingleUser(req, null, {usernameDest:'', groupnameDest}, true, shared_consts.TypeNotifs.TYPEDIR_GROUPS, shared_consts.TypeNotifs.ID_GROUP_ACCEPTED);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
|
||||
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
@@ -1779,7 +1839,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, value, true, username_action);
|
||||
ris = await MyGroup.getInfoGroupByGroupname(idapp, groupnameDest);
|
||||
}
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||
@@ -1807,12 +1867,14 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, true, username_action);
|
||||
}
|
||||
} else {
|
||||
if (foundIfAlreadyAskGroup) {
|
||||
ris = await this.removeFromMyGroups(idapp, usernameOrig,
|
||||
groupnameDest); // Rimuovo il Gruppo da me
|
||||
ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo il Gruppo da me
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1825,13 +1887,24 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
ris = await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REFUSE_REQ_GROUP) {
|
||||
|
||||
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo la richiesta di entrare nel gruppo
|
||||
console.log('ris', ris);
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.DELETE_GROUP) {
|
||||
|
||||
ris = await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
}
|
||||
ris = await MyGroup.deleteGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
@@ -1854,7 +1927,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
},
|
||||
});
|
||||
//++Todo: Send Notification to Admin and Group's manager
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -1872,6 +1945,7 @@ function getWhatToShow(idapp, username) {
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
notask_verif: 1,
|
||||
|
||||
Reference in New Issue
Block a user