- Accepted and Refused Group Entering
- Report a User
This commit is contained in:
@@ -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;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user