Notification New Group

This commit is contained in:
paoloar77
2022-07-28 23:27:51 +02:00
parent 7cda5dbb8b
commit 241e4255d4
9 changed files with 63 additions and 32 deletions

View File

@@ -235,10 +235,12 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
const whatToShow = this.getWhatToShow(idapp, groupname);
return MyGroup.findOne({
const rec = await MyGroup.findOne({
idapp,
groupname,
}, whatToShow).then((rec) => !!rec ? rec._doc : null);
}, whatToShow).lean();
return rec;
};

View File

@@ -152,11 +152,11 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
newdescr = i18n.__('<strong>%s</strong> refused your Friendship', userorig, mydescr);
}
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
recnotif.openUrl = '/group/' + paramsObj.groupNameDest;
recnotif.openUrl = '/grp/' + recnotif.paramsObj.groupNameDest;
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
newdescr = i18n.__('GROUP_CREATED', userorig, recnotif.paramsObj.groupNameDest);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
newdescr = i18n.__('GROUPS_ACCEPTED', userorig, recnotif.paramsObj.groupNameDest);
}
}
@@ -334,7 +334,7 @@ sendNotifSchema.statics.getDefaultRec = function(req) {
};
sendNotifSchema.statics.createNewNotification = async function(req, res, table, rec, typedir, typeid) {
sendNotifSchema.statics.createNewNotification = async function(req, res, paramsObj, table, rec, typedir, typeid) {
const SendNotif = this;
try {
@@ -348,7 +348,7 @@ sendNotifSchema.statics.createNewNotification = async function(req, res, table,
myrecnotif.typedir = typedir;
myrecnotif.typeid = typeid;
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
await SendNotif.sendToTheDestinations(myrecnotif, req, res, paramsObj);
return true;
} catch (e) {
@@ -375,7 +375,7 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
}
};
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res) {
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res, paramsObj) {
const SendNotif = this;
const {User} = require('../models/user');
@@ -383,6 +383,8 @@ 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:
@@ -466,7 +468,13 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
}
if (send) {
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotif.tablerec)) {
if (tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
send = true;
}
}
if (send) {
myrecnotif.dest = user.username;
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
}
@@ -484,10 +492,10 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
try {
myrecnotif.paramsObj = paramsObj;
myrecnotif.dest = paramsObj.usernameDest ? paramsObj.usernameDest : '';
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
myrecnotif.dest = paramsObj.usernameDest;
myrecnotif.paramsObj = paramsObj;
if (onlysave) {
await SendNotif.saveNotif(myrecnotif);
} else {

View File

@@ -1768,7 +1768,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
// CREATE NOTIFICATION IN TABLE SENDNOTIF
const req = tools.getReqByPar(idapp, usernameOrig);
SendNotif.create(req, null, {usernameDest:'', groupnameDest}, true, shared_consts.TypeNotifs.TYPEDIR_GROUPS, shared_consts.TypeNotifs.ID_GROUP_ACCEPTED);
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]}}}};