- Accepted and Refused Group Entering
- Report a User
This commit is contained in:
@@ -16,6 +16,13 @@
|
||||
"<strong>%s</strong> refused your Friendship": "<strong>%s</strong> refused your Friendship",
|
||||
"✅ %s accepted your Friendship request !": "✅ %s ha accettato la tua richiesta di Amicizia !",
|
||||
"✅ You have accepted %s' Friendship request!": "✅ You have accepted %s' Friendship request!",
|
||||
"GROUPS_ACCEPTED": "✅ You have been accepted by %s to join the Group %s",
|
||||
"GROUP_CREATED": "✅ A new Group created by %s called %s has been created"
|
||||
"GROUPS_ACCEPTED": "✅ You have been accepted by %s to join the Group %s (by %s)",
|
||||
"GROUPS_REFUSED": "❌ You have been denied access by %s to join the %s Group. If you think this is an error, please contact the group administrator.",
|
||||
"GROUPS_REMOVED": "❌ user %s was removed from the %s Group (by %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS": "✅ l'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)",
|
||||
"GROUP_CREATED": "✅ A new Group created by %s called %s has been created",
|
||||
"GROUP_REQUEST_TO_ENTER": "%s asked to join the group %s",
|
||||
"GROUP_REQUEST": "Richiesta di entrare nel Gruppo %s da parte di %s",
|
||||
"RICHIESTA_BLOCCO_GRUPPO": "Richiesta di bloccare il Gruppo %s da parte di %s",
|
||||
"GRUPPO_ELIMINATO": "Il gruppo %s è stato eliminato da parte di %s"
|
||||
}
|
||||
|
||||
41
src/server/locales/it.json
Executable file → Normal file
41
src/server/locales/it.json
Executable file → Normal file
@@ -1,16 +1,29 @@
|
||||
{
|
||||
"Hello": "Ciao",
|
||||
"Hello %s": "Ciao %s",
|
||||
"Good: %s": "Bene: %s",
|
||||
"Service: %s": "Servizio: %s",
|
||||
"<strong>%s</strong> new Good: %s": "<strong>%s</strong> nuovo Bene: %s",
|
||||
"<strong>%s</strong> new Service: %s": "<strong>%s</strong> nuovo Servizio: %s",
|
||||
"OPEN PAGE": "APRI PAGINA",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
||||
"<strong>%s</strong> refused your Friendship": "<strong>%s</strong> ha rifiutato l'Amicizia",
|
||||
"✅ %s accepted your Friendship request !": "✅ %s ha accettato la tua richiesta di Amicizia !",
|
||||
"✅ You have accepted %s' Friendship request!": "✅ Hai accettato la richiesta di Amicizia di %s !",
|
||||
"GROUPS_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Gruppo %s",
|
||||
"GROUP_CREATED": "✅ %s ha creato un nuovo Gruppo chiamato %s"
|
||||
"Hello": "Ciao",
|
||||
"Hello %s": "Ciao %s",
|
||||
"Good: %s": "Bene: %s",
|
||||
"Service: %s": "Servizio: %s",
|
||||
"<strong>%s</strong> new Good: %s": "<strong>%s</strong> nuovo Bene: %s",
|
||||
"<strong>%s</strong> new Service: %s": "<strong>%s</strong> nuovo Servizio: %s",
|
||||
"OPEN PAGE": "APRI PAGINA",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
||||
"<strong>%s</strong> refused your Friendship": "<strong>%s</strong> ha rifiutato l'Amicizia",
|
||||
"✅ %s accepted your Friendship request !": "✅ %s ha accettato la tua richiesta di Amicizia !",
|
||||
"✅ You have accepted %s' Friendship request!": "✅ Hai accettato la richiesta di Amicizia di %s !",
|
||||
"GROUPS_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Gruppo %s (da parte di %s)",
|
||||
"GROUPS_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Gruppo %s. Se pensi sia un'errore, contatta l'amministratore del Gruppo.",
|
||||
"GROUPS_REMOVED": "❌ l'utente %s è stato rimosso del Gruppo %s (da parte di %s)",
|
||||
"GROUPS_EXIT_USER": "❌ l'utente %s è uscito dal Gruppo %s",
|
||||
"GROUPS_EXIT_USER_TO_ME": "❌ Sei uscito dal Gruppo %s",
|
||||
"GROUPS_REMOVED_TO_ME": "❌ Sei stato rimosso dal Gruppo %s (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS": "✅ l'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)",
|
||||
"GROUP_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel gruppo %s",
|
||||
"GROUP_CREATED": "✅ %s ha creato un nuovo Gruppo chiamato %s",
|
||||
"GROUP_REQUEST": "Richiesta di entrare nel Gruppo %s da parte di %s",
|
||||
"RICHIESTA_BLOCCO_GRUPPO": "Richiesta di bloccare il Gruppo %s 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": "E' stato segnalato %s da %s per comportamenti non idonei.",
|
||||
"FRIEND_REPORTED_YOU": "Hai segnalato %s per comportamenti non idonei."
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -78,6 +78,7 @@ const UserCost = {
|
||||
'profile.teleg_id',
|
||||
'profile.manage_telegram',
|
||||
'deleted',
|
||||
'reported',
|
||||
],
|
||||
|
||||
FIELDS_REQUISITI: [
|
||||
@@ -247,6 +248,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
mydata.userId = req.user._id;
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_CREATEDBY.includes(params.table)) {
|
||||
if (!mydata.createdBy)
|
||||
mydata.createdBy = req.user.username;
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_PERM_NEWREC.includes(params.table)) {
|
||||
if (!consentito) {
|
||||
mydata.verifyrec = false;
|
||||
@@ -332,7 +338,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
let setnotif = false;
|
||||
let typedir = 0;
|
||||
let typeid = 0;
|
||||
let groupNameDest = '';
|
||||
let groupnameDest = '';
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
||||
@@ -349,12 +355,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
||||
groupNameDest = myrec ? myrec.groupname : '';
|
||||
groupnameDest = myrec ? myrec.groupname : '';
|
||||
setnotif = true;
|
||||
}
|
||||
|
||||
if (setnotif) {
|
||||
await SendNotif.createNewNotification(req, res, {groupNameDest}, params.table, myrec, typedir, typeid);
|
||||
await SendNotif.createNewNotification(req, res, {groupnameDest}, params.table, myrec, typedir, typeid);
|
||||
}
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
||||
@@ -502,6 +508,7 @@ router.post('/getexp', authenticate, (req, res) => {
|
||||
{
|
||||
username: 1,
|
||||
email: 1,
|
||||
'reported': 1,
|
||||
'profile.teleg_id': 1,
|
||||
'verified_by_aportador': 1,
|
||||
'profile.username_telegram': 1,
|
||||
|
||||
@@ -18,9 +18,11 @@ const {ObjectID} = require('mongodb');
|
||||
|
||||
async function getGroupRecAdminsInfo(idapp, data) {
|
||||
|
||||
for (const admin of data.admins) {
|
||||
const myuser = await User.findOne({idapp, username: admin.username}).lean();
|
||||
admin.profile = { img: myuser.profile.img };
|
||||
if (data && data.admins) {
|
||||
for (const admin of data.admins) {
|
||||
const myuser = await User.findOne({idapp, username: admin.username}, {'profile.img': 1}).lean();
|
||||
admin.profile = {img: myuser.profile.img};
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
@@ -424,9 +424,19 @@ router.post('/panel', authenticate, async (req, res) => {
|
||||
try {
|
||||
const myuser = await User.findOne({idapp, username},
|
||||
{
|
||||
username: 1, email: 1, verified_by_aportador: 1, aportador_solidario: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
email: 1,
|
||||
verified_by_aportador: 1,
|
||||
aportador_solidario: 1,
|
||||
lasttimeonline: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
blocked: 1,
|
||||
reported: 1,
|
||||
username_who_report: 1,
|
||||
date_report: 1,
|
||||
profile: 1,
|
||||
}).lean();
|
||||
if (!!myuser) {
|
||||
@@ -647,7 +657,7 @@ router.post('/friends/cmd', authenticate, async (req, res) => {
|
||||
usernameOrig = await User.getRealUsernameByUsername(idapp, usernameOrig);
|
||||
usernameDest = await User.getRealUsernameByUsername(idapp, usernameDest);
|
||||
|
||||
return User.setFriendsCmd(idapp, usernameOrig, usernameDest, cmd, value).
|
||||
return User.setFriendsCmd(req, idapp, usernameOrig, usernameDest, cmd, value).
|
||||
then((ris) => {
|
||||
res.send(ris);
|
||||
}).
|
||||
|
||||
@@ -575,7 +575,7 @@ async function faitest() {
|
||||
|
||||
const langdest = 'it';
|
||||
|
||||
telegrambot.askConfirmationUser(req, res, myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser);
|
||||
telegrambot.askConfirmationUser(myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -502,7 +502,7 @@ const txt = {
|
||||
MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK +
|
||||
'🚫 Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s.<br>Contattalo per farti abilitare !',
|
||||
MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK + '🚫 %s Non è stato Abilitato !',
|
||||
MSG_ISCRITTO_CONACREIS: emo.FIRE + ' Si è appena Iscritto al Conacreis "%s"',
|
||||
MSG_ISCRITTO_CONACREIS: emo.FIRE + '[%] Si è appena Iscritto al Conacreis "%s"',
|
||||
MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !',
|
||||
MSG_MSG_TOSENT: emoji.get('envelope') + ' Messaggi da Inviare',
|
||||
MSG_MSG_INCORSO: emoji.get('envelope') + ' messaggi in corso... Inviati attualmente',
|
||||
@@ -683,7 +683,7 @@ const txt_pt = {
|
||||
|
||||
const TelegramBot = require('node-telegram-bot-api');
|
||||
|
||||
const ADMIN_IDTELEGRAM_TEST = 5356627050; // 5022837609; //Perseo
|
||||
const ADMIN_IDTELEGRAM_TEST = 5356627050; // 5022837609; //Surya Arena
|
||||
|
||||
const MyTelegramBot = {
|
||||
|
||||
@@ -807,7 +807,9 @@ const MyTelegramBot = {
|
||||
let langdest = mylocalsconf.iscritto.lang;
|
||||
let NameFrom = `${mylocalsconf.iscritto.name} ${mylocalsconf.iscritto.surname}`;
|
||||
|
||||
let text = printf(getstr(langdest, 'MSG_ISCRITTO_CONACREIS'), NameFrom);
|
||||
let nomeapp = tools.getHostByIdApp(mylocalsconf.idapp);
|
||||
|
||||
let text = printf(getstr(langdest, 'MSG_ISCRITTO_CONACREIS'), nomeapp, NameFrom);
|
||||
|
||||
let addtext = '';
|
||||
|
||||
@@ -891,14 +893,24 @@ const MyTelegramBot = {
|
||||
try {
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const langdest = myuser.lang;
|
||||
|
||||
let keyb = null;
|
||||
let domanda = '';
|
||||
let sendnotif = false;
|
||||
let typedir = 0;
|
||||
let typeid = 0;
|
||||
let paramsObj = {};
|
||||
|
||||
const struserinfomsg = tools.getUserInfoMsg(idapp, myuser);
|
||||
|
||||
if (myfunc === shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
||||
sendnotif = true;
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_FRIENDS;
|
||||
typeid = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
||||
paramsObj = {usernameDest: userDest}
|
||||
|
||||
domanda = printf(tools.gettranslate('RICHIESTA_AMICIZIA', langdest), myuser.username) + '<br>' + struserinfomsg;
|
||||
|
||||
@@ -920,6 +932,13 @@ const MyTelegramBot = {
|
||||
await this.local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
|
||||
if (sendnotif) {
|
||||
const req = this.getReqByPar(idapp, username);
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, true, typedir, typeid);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error askConfirmationUser', e);
|
||||
}
|
||||
@@ -1224,7 +1243,7 @@ async function sendMsgTelegramToTheAdmin(idapp, text, msg) {
|
||||
async function setVerifiedReg(idapp, lang, usernameorig, usernameDest) {
|
||||
try {
|
||||
await User.setVerifiedByAportador(idapp, usernameorig, true);
|
||||
await User.setFriendsCmd(idapp, usernameorig, usernameDest, shared_consts.FRIENDSCMD.SETFRIEND);
|
||||
await User.setFriendsCmd(null, idapp, usernameorig, usernameDest, shared_consts.FRIENDSCMD.SETFRIEND);
|
||||
|
||||
const msgDest = printf(getstr(lang, 'MSG_APORTADOR_CONFIRMED'),
|
||||
`${usernameorig}`, usernameDest);
|
||||
@@ -3838,7 +3857,8 @@ if (true) {
|
||||
Cmd.VALIDATE_REGISTRATION, true);
|
||||
|
||||
if (changed) {
|
||||
await User.setFriendsCmd(user.idapp, data.username, userDest.username, shared_consts.FRIENDSCMD.SETFRIEND);
|
||||
const req = tools.getReqByPar(user.idapp, username_action);
|
||||
await User.setFriendsCmd(req, user.idapp, data.username, userDest.username, shared_consts.FRIENDSCMD.SETFRIEND);
|
||||
|
||||
await User.setaportador_solidario(user.idapp, data.username, userDest.username);
|
||||
|
||||
@@ -3898,7 +3918,8 @@ if (true) {
|
||||
|
||||
if (!foundIfAlreadyFriend) {
|
||||
// Aggiungilo nelle Amicizie
|
||||
const ris = await User.setFriendsCmd(user.idapp, data.username, data.userDest, cmd);
|
||||
const req = tools.getReqByPar(user.idapp, username_action);
|
||||
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
||||
|
||||
}
|
||||
|
||||
@@ -3911,7 +3932,7 @@ if (true) {
|
||||
|
||||
if (foundIfAlreadyFriend) {
|
||||
// Aggiungilo nelle Amicizie
|
||||
const ris = await User.setFriendsCmd(user.idapp, data.username, data.userDest, cmd);
|
||||
const ris = await User.setFriendsCmd(req, user.idapp, data.username, data.userDest, cmd);
|
||||
if (ris) {
|
||||
const msgDest = printf(getstr(user.lang, 'MSG_FRIENDS_NOT_ACCEPTED_CONFIRMED'), data.username);
|
||||
|
||||
|
||||
@@ -128,9 +128,7 @@ const textlang = {
|
||||
'ACCETTATO_SUL_GRUPPO': '✅ Sei stato accettato da %s a far parte del Gruppo %s',
|
||||
'CREATO_NUOVO_GRUPPO': '✅ Hai appena creato un nuovo Gruppo chiamato %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': '✅ l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
|
||||
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
'GRUPPO_ELIMINATO': 'Il gruppo %s è stato eliminato da parte di %s',
|
||||
'RICHIESTA_BLOCCO_GRUPPO': 'Richiesta di bloccare il Gruppo %s da parte di %s',
|
||||
'GROUP_REQUEST': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
},
|
||||
si: {},
|
||||
es: {
|
||||
@@ -199,7 +197,6 @@ const textlang = {
|
||||
'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s',
|
||||
'ACCETTATO_SUL_GRUPPO': 'Sei stato accettato da %s a far parte del Gruppo %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': 'l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
|
||||
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
'RICHIESTA_BLOCCO_GRUPPO': 'Richiesta di bloccare il Gruppo %s da parte di %s',
|
||||
},
|
||||
enUs: {
|
||||
@@ -263,7 +260,6 @@ const textlang = {
|
||||
'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s',
|
||||
'ACCETTATO_SUL_GRUPPO': 'Sei stato accettato da %s a far parte del Gruppo %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': 'l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
|
||||
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
'RICHIESTA_BLOCCO_GRUPPO': 'Richiesta di bloccare il Gruppo %s da parte di %s',
|
||||
},
|
||||
fr: {
|
||||
@@ -332,7 +328,6 @@ const textlang = {
|
||||
'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s',
|
||||
'ACCETTATO_SUL_GRUPPO': 'Sei stato accettato da %s a far parte del Gruppo %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': 'l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
|
||||
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
'RICHIESTA_BLOCCO_GRUPPO': 'Richiesta di bloccare il Gruppo %s da parte di %s',
|
||||
},
|
||||
pt: {
|
||||
@@ -399,7 +394,7 @@ const textlang = {
|
||||
'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s',
|
||||
'ACCETTATO_SUL_GRUPPO': 'Sei stato accettato da %s a far parte del Gruppo %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': 'l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
|
||||
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
|
||||
'RICHIESTA_BLOCCO_GRUPPO': 'Richiesta di bloccare il Gruppo %s da parte di %s',
|
||||
},
|
||||
};
|
||||
@@ -587,6 +582,7 @@ module.exports = {
|
||||
'deleted',
|
||||
'idapp',
|
||||
'tablerec',
|
||||
'extrafield',
|
||||
'idrec',
|
||||
'status'];
|
||||
},
|
||||
@@ -741,7 +737,7 @@ module.exports = {
|
||||
}
|
||||
}).
|
||||
then(ris => {
|
||||
console.log('sendNotification', ris)
|
||||
console.log('sendNotification', ris);
|
||||
}).
|
||||
catch(err => {
|
||||
console.error(err);
|
||||
@@ -862,7 +858,7 @@ module.exports = {
|
||||
},
|
||||
user: {
|
||||
username: usernameOrig,
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -895,11 +891,6 @@ module.exports = {
|
||||
|
||||
const userrecDest = await User.getUserShortDataByUsername(idapp, usernameOrig);
|
||||
|
||||
const req = this.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
SendNotif.createNewNotifToSingleUser(req, null, {usernameDest: username}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC);
|
||||
|
||||
if (userrecDest) {
|
||||
sendmynotif = false; // non lo rimandare 2 volte !
|
||||
// SEND TELEGRAM NOTIFICATION
|
||||
@@ -940,107 +931,106 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
sendNotificationByGroupname: async function(idapp, usernameOrig, groupname, cmd, telegram, username_action) {
|
||||
|
||||
var {User} = require('../models/user');
|
||||
var {MyGroup} = require('../models/mygroup');
|
||||
sendNotifGroupByUsername: async function(cmd, typeid_pass, idapp, usernameOrig, usernameDest, username_action, groupname, myrecgroup, isAdmin, username_worked) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const {User} = require('../models/user');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const group = await MyGroup.findOne({idapp, groupname},
|
||||
{_id: 1, admins: 1});
|
||||
if (!group)
|
||||
return;
|
||||
const req = this.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
// Send msg to Admins
|
||||
const user = await User.findOne({idapp, username: usernameDest},
|
||||
{_id: 1, lang: 1});
|
||||
if (user) {
|
||||
|
||||
const arrusernameAdmins = group.admins;
|
||||
let lang = user.lang;
|
||||
let paramsObj = {
|
||||
usernameDest,
|
||||
groupnameDest: groupname,
|
||||
username_action: username_action,
|
||||
singleadmin_username: usernameDest,
|
||||
options: 0,
|
||||
lang,
|
||||
isAdmin,
|
||||
username_worked,
|
||||
};
|
||||
|
||||
const myuser = await User.findOne({idapp, username: usernameOrig}).lean();
|
||||
|
||||
let struserinfomsg = this.getUserInfoMsg(idapp, myuser);
|
||||
|
||||
let objmsg = {
|
||||
title: this.getNomeAppByIdApp(idapp),
|
||||
descr: '',
|
||||
openUrl: '/',
|
||||
tag: '',
|
||||
actions: [],
|
||||
};
|
||||
|
||||
let creazionegruppo = false;
|
||||
|
||||
for (const singleadmin of arrusernameAdmins) {
|
||||
try {
|
||||
if (singleadmin.username) {
|
||||
|
||||
creazionegruppo = arrusernameAdmins.length === 1 && usernameOrig === singleadmin.username && cmd ===
|
||||
shared_consts.GROUPSCMD.SETGROUP;
|
||||
|
||||
const user = await User.findOne({idapp, username: singleadmin.username},
|
||||
{_id: 1, lang: 1});
|
||||
if (user) {
|
||||
|
||||
let userId = user._id;
|
||||
let lang = user.lang;
|
||||
|
||||
let sendnotif = true;
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||
if (creazionegruppo) {
|
||||
objmsg.descr = printf(this.get__('CREATO_NUOVO_GRUPPO', lang), groupname);
|
||||
} else {
|
||||
objmsg.descr = printf(this.get__('ACCETTATO_NOTIFICA_ADMINS', lang), usernameOrig, groupname, username_action);
|
||||
}
|
||||
objmsg.openUrl = '/grp/' + groupname;
|
||||
objmsg.tag = 'addgroups';
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||
objmsg.descr = printf(this.get__('RICHIESTA_GRUPPO', lang), groupname,
|
||||
singleadmin.username);
|
||||
objmsg.openUrl = '/grp/' + groupname;
|
||||
objmsg.tag = 'reqgroups';
|
||||
|
||||
sendnotif = false; // non lo rimandare 2 volte !
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_GRUPPO, myuser, singleadmin.username, groupname,
|
||||
group._id);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_USER) {
|
||||
objmsg.descr = printf(this.get__('RICHIESTA_BLOCCO_GRUPPO', lang),
|
||||
groupname, singleadmin.username);
|
||||
objmsg.openUrl = '/grp/' + groupname;
|
||||
objmsg.tag = 'blockgroups';
|
||||
} else if (cmd === shared_consts.GROUPSCMD.DELETE_GROUP) {
|
||||
objmsg.descr = printf(this.get__('GRUPPO_ELIMINATO', lang), groupname, username_action);
|
||||
objmsg.openUrl = '/grp/' + groupname;
|
||||
objmsg.tag = 'deletegroup';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (sendnotif && objmsg.descr && !creazionegruppo) {
|
||||
await this.sendNotifAndMsgTelegram(idapp, userId, objmsg, telegram, struserinfomsg);
|
||||
}
|
||||
let sendnotif = true;
|
||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuseringroup = await User.countUsersInGroup(idapp, groupname);
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||
if (myrecgroup && myrecgroup.createdBy === usernameDest && numuseringroup <= 1) {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
||||
} else {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_ACCEPTED;
|
||||
}
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REFUSE_REQ_GROUP) {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_REFUSED;
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP) {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_REMOVED;
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_GRUPPO, myuserdata, usernameDest, groupname, myrecgroup._id);
|
||||
onlysave = false;
|
||||
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_USER) {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_BLOCK_USER;
|
||||
} else if (cmd === shared_consts.GROUPSCMD.DELETE_GROUP) {
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_DELETE_USER;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByGroupname', e);
|
||||
|
||||
if (typeid_pass) {
|
||||
typeid = typeid_pass;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendnotif && typeid > 0) {
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||
const reclang = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
|
||||
objmsg.openUrl = '/grp/' + groupname;
|
||||
objmsg.tag = 'addgroups';
|
||||
if (creazionegruppo) {
|
||||
objmsg.descr = printf(this.get__('CREATO_NUOVO_GRUPPO', reclang.lang), groupname);
|
||||
} else {
|
||||
objmsg.descr = printf(this.get__('ACCETTATO_SUL_GRUPPO', reclang.lang), username_action, groupname);
|
||||
},
|
||||
|
||||
sendNotificationByGroupname: async function(idapp, usernameOrig, groupname, cmd, value, telegram, username_action) {
|
||||
|
||||
const {MyGroup} = require('../models/mygroup');
|
||||
const {User} = require('../models/user');
|
||||
|
||||
|
||||
const group = await MyGroup.findOne({idapp, groupname}, {_id: 1, admins: 1, createdBy: 1}).lean();
|
||||
if (!group)
|
||||
return;
|
||||
|
||||
let giainviato = false;
|
||||
|
||||
try {
|
||||
// SEND TO THE ADMINS THE NOTIFICATIONS
|
||||
for (const singleadmin of group.admins) {
|
||||
try {
|
||||
if (singleadmin.username) {
|
||||
if (usernameOrig === singleadmin.username)
|
||||
giainviato = true;
|
||||
|
||||
await this.sendNotifGroupByUsername(cmd, 0, idapp, usernameOrig, singleadmin.username, username_action, groupname, group, true);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByGroupname', e);
|
||||
}
|
||||
}
|
||||
// Send to User:
|
||||
await this.sendNotifAndMsgTelegram(idapp, reclang._id, objmsg, telegram);
|
||||
|
||||
if (!giainviato && (cmd !== shared_consts.GROUPSCMD.REQGROUP)) {
|
||||
// SEND TO THE USER THE NOTIFICATION
|
||||
await this.sendNotifGroupByUsername(cmd, value, idapp, usernameOrig, usernameOrig, username_action, groupname, false);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
},
|
||||
@@ -1131,7 +1121,7 @@ module.exports = {
|
||||
return {
|
||||
exit: true,
|
||||
ret: false,
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
exit: true,
|
||||
@@ -1208,11 +1198,11 @@ module.exports = {
|
||||
},
|
||||
|
||||
getLinkUserProfile: function(idapp, username) {
|
||||
return tools.getHostByIdApp(idapp) + '/my/' + username;
|
||||
return this.getHostByIdApp(idapp) + '/my/' + username;
|
||||
},
|
||||
|
||||
getLinkEditUserProfile: function(idapp) {
|
||||
return tools.getHostByIdApp(idapp) + '/editprofile';
|
||||
return this.getHostByIdApp(idapp) + '/editprofile';
|
||||
},
|
||||
|
||||
getConfSiteOptionEnabledByIdApp: function(idapp, option) {
|
||||
@@ -2784,7 +2774,7 @@ module.exports = {
|
||||
try {
|
||||
this.MYAPPS = await Site.findAll(0);
|
||||
// console.log('this.MYAPPS', this.MYAPPS);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('loadApps', e);
|
||||
}
|
||||
},
|
||||
@@ -2964,27 +2954,27 @@ module.exports = {
|
||||
|
||||
capitalize(value) {
|
||||
if (!value) {
|
||||
return ''
|
||||
return '';
|
||||
}
|
||||
const myval = value.toString()
|
||||
return myval.charAt(0).toUpperCase() + myval.slice(1)
|
||||
const myval = value.toString();
|
||||
return myval.charAt(0).toUpperCase() + myval.slice(1);
|
||||
},
|
||||
|
||||
firstchars(value, numchars = 200) {
|
||||
if (!value) {
|
||||
return ''
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
let mycar = value.substring(0, numchars)
|
||||
if (value.length > numchars) mycar += '...'
|
||||
return mycar
|
||||
let mycar = value.substring(0, numchars);
|
||||
if (value.length > numchars) mycar += '...';
|
||||
return mycar;
|
||||
} catch (e) {
|
||||
return value
|
||||
return value;
|
||||
}
|
||||
},
|
||||
|
||||
removeAtChar(mystr) {
|
||||
if (mystr && mystr[0] === '@'){
|
||||
if (mystr && mystr[0] === '@') {
|
||||
return mystr = mystr.substring(1);
|
||||
}
|
||||
|
||||
@@ -2994,20 +2984,20 @@ module.exports = {
|
||||
updateQueryStringParameter(uri, key, value) {
|
||||
if (uri === '')
|
||||
return '';
|
||||
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
|
||||
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
|
||||
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
||||
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
||||
if (uri.match(re)) {
|
||||
return uri.replace(re, '$1' + key + "=" + value + '$2');
|
||||
return uri.replace(re, '$1' + key + '=' + value + '$2');
|
||||
} else {
|
||||
return uri + separator + key + "=" + value;
|
||||
return uri + separator + key + '=' + value;
|
||||
}
|
||||
},
|
||||
|
||||
isArray(val) {
|
||||
return Array.isArray(val)
|
||||
return Array.isArray(val);
|
||||
},
|
||||
|
||||
getContentByTypeMsg (typemsg) {
|
||||
getContentByTypeMsg(typemsg) {
|
||||
|
||||
},
|
||||
|
||||
@@ -3021,6 +3011,6 @@ module.exports = {
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -46,6 +46,7 @@ module.exports = {
|
||||
REFUSE_REQ_FRIEND: 145,
|
||||
CANCEL_REQ_FRIEND: 146,
|
||||
BLOCK_USER: 155,
|
||||
REPORT_USER: 158,
|
||||
FIND_PEOPLE: 166,
|
||||
},
|
||||
|
||||
@@ -134,6 +135,7 @@ module.exports = {
|
||||
'circuits',
|
||||
'movements'],
|
||||
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
TABLES_CREATEDBY: ['mygroups'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'bots'],
|
||||
|
||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
@@ -203,6 +205,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
MessageOptions: {
|
||||
Notify_OnlyToNotifinApp: 1,
|
||||
Notify_ByEmail: 2,
|
||||
Notify_ByPushNotification: 4,
|
||||
Notify_ByBotTelegram: 8,
|
||||
@@ -291,14 +294,16 @@ module.exports = {
|
||||
StatusNotifs: {
|
||||
STATUS_FRIENDS_ACCEPTED: 1,
|
||||
STATUS_FRIENDS_REFUSED: 2,
|
||||
STATUS_GROUPS_ACCEPTED: 3,
|
||||
STATUS_GROUPS_REFUSED: 4,
|
||||
STATUS_FRIENDS_REPORTED: 3,
|
||||
},
|
||||
|
||||
GroupsNotifs: {
|
||||
STATUS_GROUPS_NEW: 1,
|
||||
STATUS_GROUPS_ACCEPTED: 2,
|
||||
STATUS_GROUPS_ACCEPTED: 3,
|
||||
STATUS_GROUPS_REFUSED: 4,
|
||||
STATUS_GROUPS_BLOCKED: 5,
|
||||
STATUS_GROUPS_DELETED: 6,
|
||||
STATUS_GROUPS_REMOVED: 7,
|
||||
},
|
||||
|
||||
TypeNotifs: {
|
||||
@@ -315,11 +320,16 @@ module.exports = {
|
||||
ID_FRIENDS_ACCEPTED: 2,
|
||||
ID_FRIENDS_REFUSED: 4,
|
||||
ID_FRIENDS_ACCEPTED_MY_REQUEST: 8,
|
||||
ID_FRIENDS_REPORTED: 16,
|
||||
|
||||
TYPEDIR_GROUPS: 4,
|
||||
ID_GROUP_NEW_REC: 1,
|
||||
ID_GROUP_ACCEPTED: 2,
|
||||
ID_GROUP_REFUSED: 4,
|
||||
ID_GROUP_REQUEST_TO_ENTER: 8,
|
||||
ID_GROUP_BLOCK_USER: 16,
|
||||
ID_GROUP_DELETE_USER: 32,
|
||||
ID_GROUP_REMOVED: 64,
|
||||
|
||||
TYPEDIR_CIRCUITS: 5,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user