- 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:
@@ -25,5 +25,8 @@
|
|||||||
"GRUPPO_ELIMINATO": "Il gruppo %s è stato eliminato da parte di %s",
|
"GRUPPO_ELIMINATO": "Il gruppo %s è stato eliminato da parte di %s",
|
||||||
"FRIEND_REPORTED_TO_ME": "Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti",
|
"FRIEND_REPORTED_TO_ME": "Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti",
|
||||||
"FRIEND_REPORTED": "E' stato segnalato %s da %s per comportamenti non idonei.",
|
"FRIEND_REPORTED": "E' stato segnalato %s da %s per comportamenti non idonei.",
|
||||||
"FRIEND_REPORTED_YOU": "Hai segnalato %s per comportamenti non idonei."
|
"FRIEND_REPORTED_YOU": "Hai segnalato %s per comportamenti non idonei.",
|
||||||
|
"FRIEND_UNBLOCKED_TO_ME": "Sei stato riattivato da %s",
|
||||||
|
"FRIEND_UNBLOCKED": "E' stato riattivato %s da %s.",
|
||||||
|
"FRIEND_UNBLOCKED_YOU": "Hai riattivato %s."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.level = 'F';
|
mongoose.level = 'F';
|
||||||
|
|
||||||
@@ -99,6 +98,12 @@ const MyGroupSchema = new Schema({
|
|||||||
username: {type: String},
|
username: {type: String},
|
||||||
date: {type: Date},
|
date: {type: Date},
|
||||||
}], // username
|
}], // username
|
||||||
|
refused_users: [
|
||||||
|
{
|
||||||
|
_id: false,
|
||||||
|
username: {type: String},
|
||||||
|
date: {type: Date},
|
||||||
|
}], // username
|
||||||
deleted: {
|
deleted: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@@ -112,7 +117,7 @@ MyGroupSchema.statics.getFieldsForSearch = function() {
|
|||||||
MyGroupSchema.statics.executeQueryTable = function(idapp, params, user) {
|
MyGroupSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||||
params.fieldsearch = this.getFieldsForSearch();
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
|
|
||||||
const { User } = require('./user');
|
const {User} = require('./user');
|
||||||
|
|
||||||
if (params.options) {
|
if (params.options) {
|
||||||
if (tools.isBitActive(params.options, shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
|
if (tools.isBitActive(params.options, shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
|
||||||
@@ -144,8 +149,6 @@ MyGroupSchema.pre('save', async function(next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MyGroupSchema.statics.findAllIdApp = async function(idapp) {
|
MyGroupSchema.statics.findAllIdApp = async function(idapp) {
|
||||||
const myfind = {idapp};
|
const myfind = {idapp};
|
||||||
|
|
||||||
@@ -171,7 +174,23 @@ MyGroupSchema.statics.removeReqGroup = async function(idapp, username, groupname
|
|||||||
{$pull: {req_users: {username: {$in: [username]}}}});
|
{$pull: {req_users: {username: {$in: [username]}}}});
|
||||||
};
|
};
|
||||||
|
|
||||||
MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
// Aggiungi agli utenti Rifiutati del Gruppo
|
||||||
|
MyGroupSchema.statics.refuseReqGroup = async function(idapp, username, groupnameDest) {
|
||||||
|
|
||||||
|
return MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||||
|
{
|
||||||
|
$push:
|
||||||
|
{
|
||||||
|
refused_users: {
|
||||||
|
username,
|
||||||
|
date: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getWhatToShow = function(idapp, username) {
|
||||||
// FOR ME, PERMIT ALL
|
// FOR ME, PERMIT ALL
|
||||||
return {
|
return {
|
||||||
groupname: 1,
|
groupname: 1,
|
||||||
@@ -189,11 +208,12 @@ MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
|||||||
admins: 1,
|
admins: 1,
|
||||||
blocked: 1,
|
blocked: 1,
|
||||||
req_users: 1,
|
req_users: 1,
|
||||||
|
refused_users: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
MyGroupSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||||
return {
|
return {
|
||||||
groupname: 1,
|
groupname: 1,
|
||||||
title: 1,
|
title: 1,
|
||||||
@@ -204,7 +224,7 @@ MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
|||||||
idCity: 1,
|
idCity: 1,
|
||||||
note: 1,
|
note: 1,
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
||||||
idapp, groupname, field) {
|
idapp, groupname, field) {
|
||||||
@@ -227,13 +247,6 @@ MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MyGroupSchema.statics.getUsernameReqGroupsByGroupname = async function(
|
|
||||||
idapp, groupname) {
|
|
||||||
|
|
||||||
return this.getArrUsernameFromFieldByGroupname(idapp, groupname, 'req_users');
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname) {
|
MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname) {
|
||||||
|
|
||||||
const whatToShow = this.getWhatToShow(idapp, groupname);
|
const whatToShow = this.getWhatToShow(idapp, groupname);
|
||||||
@@ -252,8 +265,6 @@ MyGroupSchema.statics.deleteGroup = async function(idapp, usernameOrig, groupnam
|
|||||||
return MyGroup.findOneAndRemove({idapp, groupname});
|
return MyGroup.findOneAndRemove({idapp, groupname});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req) {
|
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -300,11 +311,21 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
|||||||
{deleted: {$exists: true, $eq: false}}],
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
}, whatToShow_Unknown);
|
}, whatToShow_Unknown);
|
||||||
|
|
||||||
|
let listRefusedGroups = await MyGroup.find({
|
||||||
|
idapp,
|
||||||
|
'refused_users': {
|
||||||
|
$elemMatch: {username: {$eq: username}},
|
||||||
|
},
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, whatToShow_Unknown);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
listUsersGroup,
|
listUsersGroup,
|
||||||
listgroups,
|
listgroups,
|
||||||
//listRequestUsersGroup,
|
|
||||||
listSentRequestGroups,
|
listSentRequestGroups,
|
||||||
|
listRefusedGroups,
|
||||||
mygroups: req.user.profile.mygroups,
|
mygroups: req.user.profile.mygroups,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -317,6 +338,7 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
|||||||
listRequestUsersGroup: [],
|
listRequestUsersGroup: [],
|
||||||
listTrusted: [],
|
listTrusted: [],
|
||||||
listSentRequestGroups: [],
|
listSentRequestGroups: [],
|
||||||
|
listRefusedGroups: [],
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -177,6 +177,15 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
|||||||
} else {
|
} else {
|
||||||
newdescr = i18n.__('FRIEND_REPORTED_TO_ME', recnotif.paramsObj.username_action, recnotif.paramsObj.username_action);
|
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) {
|
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||||
tag = 'group';
|
tag = 'group';
|
||||||
@@ -184,9 +193,9 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
|||||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
|
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) {
|
} 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);
|
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);
|
newdescr = i18n.__('GROUPS_ACCEPTED', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||||
tag = 'addgroup';
|
tag = 'addgroup';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REMOVED) {
|
} 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);
|
newdescr = i18n.__('GRUPPO_ELIMINATO', userorig, recnotif.paramsObj.username_action);
|
||||||
tag = 'deletegroup';
|
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;
|
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());
|
// console.log('myrecout._id', myrecout._id.toString());
|
||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
await myrecout.save().then(async (res) => {
|
let res = null;
|
||||||
|
try {
|
||||||
|
res = await myrecout.save();
|
||||||
if (res) {
|
if (res) {
|
||||||
const idobj = res._id;
|
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);
|
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).catch((e) => {
|
} catch(e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
return null;
|
return null;
|
||||||
});
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
|
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 SendNotif = this;
|
||||||
|
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
@@ -504,7 +521,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
|||||||
|
|
||||||
// Send only to the destination to reach:
|
// Send only to the destination to reach:
|
||||||
const userlist = await User.find({
|
const userlist = await User.find({
|
||||||
idapp: myrecnotif.idapp,
|
idapp: myrecnotifpass.idapp,
|
||||||
$or: [
|
$or: [
|
||||||
{deleted: {$exists: false}},
|
{deleted: {$exists: false}},
|
||||||
{deleted: {$exists: true, $eq: false}}],
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
@@ -525,39 +542,40 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
|||||||
let arrregions = [];
|
let arrregions = [];
|
||||||
let idSector = 0;
|
let idSector = 0;
|
||||||
|
|
||||||
const mytable = globalTables.getTableByTableName(myrecnotif.tablerec);
|
const mytable = globalTables.getTableByTableName(myrecnotifpass.tablerec);
|
||||||
|
|
||||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotif.tablerec) ||
|
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotif.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) {
|
if (myrectableorig) {
|
||||||
for (const city of myrectableorig.idCity) {
|
for (const city of myrectableorig.idCity) {
|
||||||
arrprovinces.push(await City.getProvinceByIdCity(city));
|
arrprovinces.push(await City.getProvinceByIdCity(city));
|
||||||
arrregions.push(await City.getRegionByIdCity(city));
|
arrregions.push(await City.getRegionByIdCity(city));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myrecnotif.tablerec === shared_consts.TABLES_MYGOODS) {
|
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||||
idSector = myrectableorig.idSectorGood;
|
idSector = myrectableorig.idSectorGood;
|
||||||
} else {
|
} else {
|
||||||
idSector = myrectableorig.idSector;
|
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) {
|
for (const user of userlist) {
|
||||||
|
|
||||||
if (user.profile.notifs) {
|
if (user.profile && user.profile.notifs) {
|
||||||
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotif.typedir);
|
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotifpass.typedir);
|
||||||
|
|
||||||
let send = false;
|
let send = false;
|
||||||
|
|
||||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotif.tablerec) ||
|
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||||
// Estrai la Città, la Provincia e la regione.
|
// Estrai la Città, la Provincia e la regione.
|
||||||
|
|
||||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
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)) {
|
if (idSector && usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_SECTOR)) {
|
||||||
// Controlla se è del settore selezionato
|
// 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) {
|
if (user.profile.notif_sector_goods) {
|
||||||
send = send && (user.profile.notif_sector_goods.includes(idSector));
|
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)) {
|
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
|
||||||
send = true;
|
send = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (send) {
|
if (send) {
|
||||||
|
let myrecnotif = new SendNotif(myrecnotifpass);
|
||||||
myrecnotif.dest = user.username;
|
myrecnotif.dest = user.username;
|
||||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1777,6 +1777,36 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
|
|||||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (cmd === shared_consts.FRIENDSCMD.UNBLOCK_USER) {
|
||||||
|
|
||||||
|
username_worked = usernameDest;
|
||||||
|
|
||||||
|
// Sblocco la persona
|
||||||
|
ris = await User.updateOne({idapp, username: username_worked}, {
|
||||||
|
$set: {
|
||||||
|
reported: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ris) {
|
||||||
|
// Send a notification to the DESTINATION!
|
||||||
|
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||||
|
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
|
||||||
|
|
||||||
|
// 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_UNBLOCKED);
|
||||||
|
|
||||||
|
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_UNBLOCKED);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1832,8 +1862,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
|||||||
|
|
||||||
// Elimina la richiesta:
|
// Elimina la richiesta:
|
||||||
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
|
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
|
||||||
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
|
||||||
update);
|
|
||||||
|
// Elimina eventualmente se era bloccato:
|
||||||
|
update = {$pull: {refused_users: {username: {$in: [usernameOrig]}}}};
|
||||||
|
await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
|
||||||
} else {
|
} else {
|
||||||
ris = false;
|
ris = false;
|
||||||
}
|
}
|
||||||
@@ -1892,6 +1925,8 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
|||||||
|
|
||||||
} else if (cmd === shared_consts.GROUPSCMD.REFUSE_REQ_GROUP) {
|
} else if (cmd === shared_consts.GROUPSCMD.REFUSE_REQ_GROUP) {
|
||||||
|
|
||||||
|
ris = await MyGroup.refuseReqGroup(idapp, usernameOrig, groupnameDest); // Aggiungi alla lista utenti Rifiutati
|
||||||
|
|
||||||
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo la richiesta di entrare nel gruppo
|
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo la richiesta di entrare nel gruppo
|
||||||
console.log('ris', ris);
|
console.log('ris', ris);
|
||||||
|
|
||||||
@@ -3443,6 +3478,20 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
|||||||
? listSentMyRequestGroups
|
? listSentMyRequestGroups
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const listRefusedGroups = await MyGroup.find({
|
||||||
|
idapp,
|
||||||
|
'refused_users': {
|
||||||
|
$elemMatch: {username: {$eq: recUser.username}},
|
||||||
|
},
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, MyGroup.getWhatToShow_Unknown()).lean();
|
||||||
|
|
||||||
|
recUser._doc.profile.refused_groups = listRefusedGroups
|
||||||
|
? listRefusedGroups
|
||||||
|
: [];
|
||||||
|
|
||||||
const listManageGroups = await MyGroup.find({
|
const listManageGroups = await MyGroup.find({
|
||||||
idapp,
|
idapp,
|
||||||
'admins': {
|
'admins': {
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ router.post('/', authenticate, (req, res) => {
|
|||||||
|
|
||||||
recmsg.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
|
recmsg.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
|
||||||
recmsg.typeid = shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC;
|
recmsg.typeid = shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC;
|
||||||
return await SendNotif.saveAndSendNotif(recmyevent, req, res).then((out) => {
|
// ##Todo !! DA SISTEMARE !!!
|
||||||
|
return await SendNotif.saveAndSendNotif(recmsg, req, res).then((out) => {
|
||||||
if (out)
|
if (out)
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
|
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -937,7 +937,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
sendNotifGroupByUsername: async function(
|
sendNotifGroupByUsername: async function(
|
||||||
cmd, typeid_pass, idapp, usernameOrig, usernameDest, username_action, groupname, myrecgroup, isAdmin, username_worked) {
|
cmd, idapp, usernameOrig, usernameDest, username_action, groupname, myrecgroup, isAdmin, username_worked) {
|
||||||
|
|
||||||
const {SendNotif} = require('../models/sendnotif');
|
const {SendNotif} = require('../models/sendnotif');
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
@@ -991,9 +991,6 @@ module.exports = {
|
|||||||
typeid = shared_consts.TypeNotifs.ID_GROUP_DELETE_USER;
|
typeid = shared_consts.TypeNotifs.ID_GROUP_DELETE_USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeid_pass) {
|
|
||||||
typeid = typeid_pass;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendnotif && typeid > 0) {
|
if (sendnotif && typeid > 0) {
|
||||||
@@ -1023,7 +1020,7 @@ module.exports = {
|
|||||||
if (usernameOrig === singleadmin.username)
|
if (usernameOrig === singleadmin.username)
|
||||||
giainviato = true;
|
giainviato = true;
|
||||||
|
|
||||||
await this.sendNotifGroupByUsername(cmd, 0, idapp, usernameOrig, singleadmin.username, username_action, groupname, group, true);
|
await this.sendNotifGroupByUsername(cmd, idapp, usernameOrig, singleadmin.username, username_action, groupname, group, true);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('sendNotificationByGroupname', e);
|
console.error('sendNotificationByGroupname', e);
|
||||||
@@ -1032,9 +1029,11 @@ module.exports = {
|
|||||||
|
|
||||||
if (!giainviato && (cmd !== shared_consts.GROUPSCMD.REQGROUP)) {
|
if (!giainviato && (cmd !== shared_consts.GROUPSCMD.REQGROUP)) {
|
||||||
// SEND TO THE USER THE NOTIFICATION
|
// SEND TO THE USER THE NOTIFICATION
|
||||||
await this.sendNotifGroupByUsername(cmd, value, idapp, usernameOrig, usernameOrig, username_action, groupname, false);
|
await this.sendNotifGroupByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, groupname, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('e', e);
|
console.error('e', e);
|
||||||
}
|
}
|
||||||
@@ -1652,17 +1651,6 @@ module.exports = {
|
|||||||
numrowend = 1;
|
numrowend = 1;
|
||||||
|
|
||||||
if (params.querytype === shared_consts.QUERYTYPE_MYGROUP) {
|
if (params.querytype === shared_consts.QUERYTYPE_MYGROUP) {
|
||||||
// query.push({'$addFields': {'myid': {'$toObjectId': params.myid}}});
|
|
||||||
/*query.push({
|
|
||||||
$match: {
|
|
||||||
$and: [
|
|
||||||
{idapp},
|
|
||||||
{'_id': '$myid'},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
*/
|
|
||||||
query.push({
|
query.push({
|
||||||
$match: {
|
$match: {
|
||||||
$expr: {
|
$expr: {
|
||||||
@@ -1700,6 +1688,44 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
} else if (params.querytype === shared_consts.QUERYTYPE_REFUSED_USER_GRP) {
|
||||||
|
query.push({
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$eq: ['$_id', params.myid],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
query.push({$project: {refused_users: 1}});
|
||||||
|
const qa1 = this.getLookup(
|
||||||
|
{
|
||||||
|
lk_tab: 'users',
|
||||||
|
lk_LF: 'refused_users.username',
|
||||||
|
lk_FF: 'username',
|
||||||
|
lk_as: 'user',
|
||||||
|
}, 0, {
|
||||||
|
'user.idapp': 1,
|
||||||
|
'user.username': 1,
|
||||||
|
'user.profile.img': 1,
|
||||||
|
'user.profile.qualifica': 1,
|
||||||
|
});
|
||||||
|
if (qa1) query = [...query, ...qa1];
|
||||||
|
query.push({$unwind: '$user'});
|
||||||
|
query.push({
|
||||||
|
$match: {
|
||||||
|
$and: [
|
||||||
|
{'user.idapp': idapp},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
query.push({
|
||||||
|
$replaceRoot: {
|
||||||
|
newRoot: '$user',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newvers) {
|
if (newvers) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
QUERYTYPE_MYGROUP: 1,
|
QUERYTYPE_MYGROUP: 1,
|
||||||
|
QUERYTYPE_REFUSED_USER_GRP: 2,
|
||||||
|
|
||||||
ALL_SAW_AND_ACCEPTED: 3,
|
ALL_SAW_AND_ACCEPTED: 3,
|
||||||
// ---------------------
|
// ---------------------
|
||||||
@@ -46,6 +47,7 @@ module.exports = {
|
|||||||
REFUSE_REQ_FRIEND: 145,
|
REFUSE_REQ_FRIEND: 145,
|
||||||
CANCEL_REQ_FRIEND: 146,
|
CANCEL_REQ_FRIEND: 146,
|
||||||
BLOCK_USER: 155,
|
BLOCK_USER: 155,
|
||||||
|
UNBLOCK_USER: 156,
|
||||||
REPORT_USER: 158,
|
REPORT_USER: 158,
|
||||||
FIND_PEOPLE: 166,
|
FIND_PEOPLE: 166,
|
||||||
},
|
},
|
||||||
@@ -321,6 +323,7 @@ module.exports = {
|
|||||||
ID_FRIENDS_REFUSED: 4,
|
ID_FRIENDS_REFUSED: 4,
|
||||||
ID_FRIENDS_ACCEPTED_MY_REQUEST: 8,
|
ID_FRIENDS_ACCEPTED_MY_REQUEST: 8,
|
||||||
ID_FRIENDS_REPORTED: 16,
|
ID_FRIENDS_REPORTED: 16,
|
||||||
|
ID_FRIENDS_UNBLOCKED: 32,
|
||||||
|
|
||||||
TYPEDIR_GROUPS: 4,
|
TYPEDIR_GROUPS: 4,
|
||||||
ID_GROUP_NEW_REC: 1,
|
ID_GROUP_NEW_REC: 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user