- Refused User
- Report User - Unblock User - refresh tables when an action (setFriends and setGroups) occurred. - fix duplicate call of loadsite
This commit is contained in:
@@ -177,6 +177,15 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
} else {
|
||||
newdescr = i18n.__('FRIEND_REPORTED_TO_ME', recnotif.paramsObj.username_action, recnotif.paramsObj.username_action);
|
||||
}
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED) {
|
||||
tag = 'unblockeduser';
|
||||
if (recnotif.paramsObj.usernameDest === recnotif.paramsObj.username_action) {
|
||||
newdescr = i18n.__('FRIEND_UNBLOCKED_YOU', recnotif.paramsObj.username_worked);
|
||||
} else if (recnotif.paramsObj.isAdmin) {
|
||||
newdescr = i18n.__('FRIEND_UNBLOCKED', recnotif.paramsObj.usernameDest, userorig);
|
||||
} else {
|
||||
newdescr = i18n.__('FRIEND_UNBLOCKED_TO_ME', recnotif.paramsObj.username_action, recnotif.paramsObj.username_action);
|
||||
}
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
tag = 'group';
|
||||
@@ -184,9 +193,9 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
|
||||
newdescr = i18n.__('GROUP_CREATED', userorig, recnotif.paramsObj.groupnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
if (recnotif.paramsObj.isAdmin)
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
else
|
||||
} 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) {
|
||||
@@ -215,6 +224,11 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
newdescr = i18n.__('GRUPPO_ELIMINATO', userorig, recnotif.paramsObj.username_action);
|
||||
tag = 'deletegroup';
|
||||
}
|
||||
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
// If is a Admin, then click to see the user's profile
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
}
|
||||
}
|
||||
|
||||
recnotif.tag = recnotif.tag ? recnotif.tag : tag;
|
||||
@@ -289,7 +303,9 @@ sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res,
|
||||
// console.log('myrecout._id', myrecout._id.toString());
|
||||
|
||||
if (save) {
|
||||
await myrecout.save().then(async (res) => {
|
||||
let res = null;
|
||||
try {
|
||||
res = await myrecout.save();
|
||||
if (res) {
|
||||
const idobj = res._id;
|
||||
|
||||
@@ -299,10 +315,11 @@ sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res,
|
||||
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||
}
|
||||
|
||||
}).catch((e) => {
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
return await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
|
||||
}
|
||||
@@ -492,7 +509,7 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res) {
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, req, res) {
|
||||
const SendNotif = this;
|
||||
|
||||
const {User} = require('../models/user');
|
||||
@@ -504,7 +521,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
|
||||
// Send only to the destination to reach:
|
||||
const userlist = await User.find({
|
||||
idapp: myrecnotif.idapp,
|
||||
idapp: myrecnotifpass.idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
@@ -525,39 +542,40 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
let arrregions = [];
|
||||
let idSector = 0;
|
||||
|
||||
const mytable = globalTables.getTableByTableName(myrecnotif.tablerec);
|
||||
const mytable = globalTables.getTableByTableName(myrecnotifpass.tablerec);
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotif.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
|
||||
const myrectableorig = await mytable.findOne({_id: myrecnotif.idrec}).lean();
|
||||
const myrectableorig = await mytable.findOne({_id: myrecnotifpass.idrec}).lean();
|
||||
if (myrectableorig) {
|
||||
for (const city of myrectableorig.idCity) {
|
||||
arrprovinces.push(await City.getProvinceByIdCity(city));
|
||||
arrregions.push(await City.getRegionByIdCity(city));
|
||||
}
|
||||
|
||||
if (myrecnotif.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
idSector = myrectableorig.idSectorGood;
|
||||
} else {
|
||||
idSector = myrectableorig.idSector;
|
||||
}
|
||||
|
||||
}
|
||||
myrecnotif.myrectableorig = myrectableorig;
|
||||
myrecnotifpass.myrectableorig = myrectableorig;
|
||||
}
|
||||
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
myrecnotifpass = this.getDescrAndLinkByRecNotif(myrecnotifpass);
|
||||
delete myrecnotifpass._doc['_id'];
|
||||
|
||||
for (const user of userlist) {
|
||||
|
||||
if (user.profile.notifs) {
|
||||
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotif.typedir);
|
||||
if (user.profile && user.profile.notifs) {
|
||||
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotifpass.typedir);
|
||||
|
||||
let send = false;
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotif.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
// Estrai la Città, la Provincia e la regione.
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
||||
@@ -572,7 +590,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
|
||||
if (idSector && usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_SECTOR)) {
|
||||
// Controlla se è del settore selezionato
|
||||
if (myrecnotif.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
if (user.profile.notif_sector_goods) {
|
||||
send = send && (user.profile.notif_sector_goods.includes(idSector));
|
||||
}
|
||||
@@ -583,13 +601,14 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (send) {
|
||||
let myrecnotif = new SendNotif(myrecnotifpass);
|
||||
myrecnotif.dest = user.username;
|
||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user