Friends Notification
Starting Group Create Notification...
This commit is contained in:
@@ -13,5 +13,7 @@
|
||||
"OPEN PAGE": "OPEN PAGE",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> asked you for Friendship",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> accepted your Friendship",
|
||||
"<strong>%s</strong> refused your Friendship": "<strong>%s</strong> refused your Friendship"
|
||||
"<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!"
|
||||
}
|
||||
|
||||
@@ -8,5 +8,7 @@
|
||||
"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"
|
||||
"<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 !"
|
||||
}
|
||||
|
||||
@@ -145,7 +145,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
|
||||
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
|
||||
} else if ((recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) ||
|
||||
(recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST)) {
|
||||
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);
|
||||
@@ -258,30 +259,38 @@ sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_REFUSED;
|
||||
}
|
||||
if (newstatus) {
|
||||
const fields_to_update = {
|
||||
status: newstatus,
|
||||
read: true,
|
||||
};
|
||||
} 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 query = {
|
||||
idapp: myrecnotif.idapp,
|
||||
typedir: myrecnotif.typedir,
|
||||
typeid: typeidsearch,
|
||||
dest: myrecnotif.sender,
|
||||
deleted: false,
|
||||
status: 0,
|
||||
};
|
||||
if (newstatus) {
|
||||
const fields_to_update = {
|
||||
status: newstatus,
|
||||
read: true,
|
||||
};
|
||||
|
||||
// Cerca il record e se lo trova lo aggiorna
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
|
||||
new: false,
|
||||
returnNewDocument: true
|
||||
});
|
||||
const query = {
|
||||
idapp: myrecnotif.idapp,
|
||||
typedir: myrecnotif.typedir,
|
||||
typeid: typeidsearch,
|
||||
dest: myrecnotif.sender,
|
||||
deleted: false,
|
||||
status: 0,
|
||||
};
|
||||
|
||||
if (myrec) {
|
||||
return myrec._doc;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ const {MyGroup} = require('../models/mygroup');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const i18n = require('i18n');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
@@ -476,7 +478,7 @@ UserSchema.statics.canHavePower = function(perm) {
|
||||
try {
|
||||
let consentito = false;
|
||||
if (User.isAdmin(perm) || User.isManager(perm) ||
|
||||
User.isEditor(perm) || User.isTutor(perm)) {
|
||||
User.isEditor(perm) || User.isFacilitatore(perm)) {
|
||||
consentito = true;
|
||||
}
|
||||
|
||||
@@ -531,7 +533,7 @@ UserSchema.statics.isDepartment = function(perm) {
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.isTutor = function(perm) {
|
||||
UserSchema.statics.isFacilitatore = function(perm) {
|
||||
try {
|
||||
return ((perm & shared_consts.Permissions.Facilitatore) ===
|
||||
shared_consts.Permissions.Facilitatore);
|
||||
@@ -1561,6 +1563,8 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
@@ -1595,12 +1599,31 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
update = {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
if (ris) {
|
||||
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);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
}catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Controlla se lui aveva già la mia amicizia
|
||||
@@ -1723,6 +1746,8 @@ UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupn
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
@@ -1743,7 +1768,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
// 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);
|
||||
SendNotif.create(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]}}}};
|
||||
|
||||
@@ -230,12 +230,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
if (User.isAdmin(req.user.perm) || User.isManager(req.user.perm) ||
|
||||
User.isEditor(req.user.perm) || User.isTutor(req.user.perm)) {
|
||||
User.isEditor(req.user.perm) || User.isFacilitatore(req.user.perm)) {
|
||||
consentito = true;
|
||||
}
|
||||
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isEditor(req.user.perm) && !User.isTutor(req.user.perm)) &&
|
||||
!User.isEditor(req.user.perm) && !User.isFacilitatore(req.user.perm)) &&
|
||||
!tools.ModificheConsentite(params.table, fieldsvalue)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
@@ -355,6 +355,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
setnotif = true;
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
||||
typeid = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
||||
setnotif = true;
|
||||
}
|
||||
|
||||
if (setnotif) {
|
||||
SendNotif.createNewNotification(req, res, params.table, myrec, typedir, typeid);
|
||||
}
|
||||
@@ -475,7 +481,7 @@ router.post('/getexp', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isTutor(req.user.perm))) {
|
||||
!User.isFacilitatore(req.user.perm))) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
@@ -591,7 +597,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isEditor(req.user.perm) && !User.isTutor(req.user.perm)) &&
|
||||
!User.isEditor(req.user.perm) && !User.isFacilitatore(req.user.perm)) &&
|
||||
(req.user._id.toString() !== id) &&
|
||||
!tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
||||
// If without permissions, exit
|
||||
@@ -798,7 +804,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
|
||||
if (!entra) {
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isTutor(req.user.perm)) && (req.user._id.toString() !== id)) {
|
||||
!User.isFacilitatore(req.user.perm)) && (req.user._id.toString() !== id)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
@@ -854,7 +860,7 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
if (!entra) {
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isTutor(req.user.perm)) && (req.user._id.toString() !== id)) {
|
||||
!User.isFacilitatore(req.user.perm)) && (req.user._id.toString() !== id)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
|
||||
@@ -119,7 +119,7 @@ router.post('/send', authenticate, async (req, res) => {
|
||||
let nummsg = 0;
|
||||
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isTutor(req.user.perm))) {
|
||||
!User.isFacilitatore(req.user.perm))) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
|
||||
@@ -494,8 +494,6 @@ const txt = {
|
||||
' Si è appena Registrato "%s" (n. %s)\nInvitato da %s',
|
||||
MSG_APORTADOR_ASK_CONFIRM: '🆕💥 🧍♂️ Abilita Nuova Registrazione:',
|
||||
MSG_ACCEPT_NEWENTRY_INGROUP: '❇️👥 🧍♂️ Accetta Ingresso nel GRUPPO %s:',
|
||||
MSG_FRIENDS_ACCEPTED: '✅ %s ha accettato la tua richiesta di Amicizia !',
|
||||
MSG_FRIENDS_ACCEPTED_CONFIRMED: '✅ Hai accettato la richiesta di Amicizia di %s !',
|
||||
MSG_FRIENDS_NOT_ACCEPTED_CONFIRMED: '🚫 Hai rifiutato la richiesta di Amicizia di %s !',
|
||||
MSG_APORTADOR_CONFIRMED: '✅ %s è stato Abilitato correttamente (da %s)!',
|
||||
MSG_APORTADOR_DEST_CONFIRMED: '✅ Sei stato Abilitato correttamente da %s!\n' +
|
||||
@@ -3901,13 +3899,6 @@ if (true) {
|
||||
if (!foundIfAlreadyFriend) {
|
||||
// Aggiungilo nelle Amicizie
|
||||
const ris = await User.setFriendsCmd(user.idapp, data.username, data.userDest, cmd);
|
||||
if (ris) {
|
||||
const msgOrig = printf(getstr(userDest.lang, 'MSG_FRIENDS_ACCEPTED', data.userDest));
|
||||
const msgDest = printf(getstr(user.lang, 'MSG_FRIENDS_ACCEPTED_CONFIRMED'), data.username);
|
||||
|
||||
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
||||
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ module.exports = {
|
||||
|
||||
TABLES_ADV_NOTIFICATION: ['myskills', 'myhosps', 'mygoods'],
|
||||
TABLES_EVENTS_NOTIFICATION: ['mybachecas'],
|
||||
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
||||
|
||||
TABLES_ID_NUMBER: [
|
||||
'permissions',
|
||||
@@ -290,7 +291,8 @@ module.exports = {
|
||||
StatusNotifs: {
|
||||
STATUS_FRIENDS_ACCEPTED: 1,
|
||||
STATUS_FRIENDS_REFUSED: 2,
|
||||
|
||||
STATUS_GROUPS_ACCEPTED: 3,
|
||||
STATUS_GROUPS_REFUSED: 4,
|
||||
},
|
||||
|
||||
TypeNotifs: {
|
||||
@@ -306,10 +308,12 @@ module.exports = {
|
||||
ID_FRIENDS_NEW_REC: 1,
|
||||
ID_FRIENDS_ACCEPTED: 2,
|
||||
ID_FRIENDS_REFUSED: 3,
|
||||
ID_FRIENDS_ACCEPTED_MY_REQUEST: 4,
|
||||
|
||||
TYPEDIR_GROUPS: 4,
|
||||
ID_GROUP_NEW_REC: 1,
|
||||
ID_GROUP_ACCEPTED: 2,
|
||||
ID_GROUP_REFUSED: 3,
|
||||
|
||||
TYPEDIR_CIRCUITS: 5,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user