Notification New Group
This commit is contained in:
@@ -15,5 +15,7 @@
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> accepted 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!"
|
||||
"✅ 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"
|
||||
}
|
||||
|
||||
@@ -10,5 +10,7 @@
|
||||
"<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 !"
|
||||
"✅ 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"
|
||||
}
|
||||
|
||||
@@ -235,10 +235,12 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, groupname);
|
||||
|
||||
return MyGroup.findOne({
|
||||
const rec = await MyGroup.findOne({
|
||||
idapp,
|
||||
groupname,
|
||||
}, whatToShow).then((rec) => !!rec ? rec._doc : null);
|
||||
}, whatToShow).lean();
|
||||
|
||||
return rec;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -152,11 +152,11 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
newdescr = i18n.__('<strong>%s</strong> refused your Friendship', userorig, mydescr);
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
recnotif.openUrl = '/group/' + paramsObj.groupNameDest;
|
||||
recnotif.openUrl = '/grp/' + recnotif.paramsObj.groupNameDest;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
|
||||
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
|
||||
newdescr = i18n.__('GROUP_CREATED', userorig, recnotif.paramsObj.groupNameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
|
||||
newdescr = i18n.__('GROUPS_ACCEPTED', userorig, recnotif.paramsObj.groupNameDest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ sendNotifSchema.statics.getDefaultRec = function(req) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.createNewNotification = async function(req, res, table, rec, typedir, typeid) {
|
||||
sendNotifSchema.statics.createNewNotification = async function(req, res, paramsObj, table, rec, typedir, typeid) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -348,7 +348,7 @@ sendNotifSchema.statics.createNewNotification = async function(req, res, table,
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
|
||||
await SendNotif.sendToTheDestinations(myrecnotif, req, res, paramsObj);
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -375,7 +375,7 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res) {
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res, paramsObj) {
|
||||
const SendNotif = this;
|
||||
|
||||
const {User} = require('../models/user');
|
||||
@@ -383,6 +383,8 @@ 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:
|
||||
@@ -466,6 +468,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)) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (send) {
|
||||
myrecnotif.dest = user.username;
|
||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||
@@ -484,10 +492,10 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
|
||||
|
||||
try {
|
||||
|
||||
myrecnotif.paramsObj = paramsObj;
|
||||
myrecnotif.dest = paramsObj.usernameDest ? paramsObj.usernameDest : '';
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
|
||||
myrecnotif.dest = paramsObj.usernameDest;
|
||||
myrecnotif.paramsObj = paramsObj;
|
||||
if (onlysave) {
|
||||
await SendNotif.saveNotif(myrecnotif);
|
||||
} else {
|
||||
|
||||
@@ -1768,7 +1768,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
SendNotif.create(req, null, {usernameDest:'', groupnameDest}, true, shared_consts.TypeNotifs.TYPEDIR_GROUPS, shared_consts.TypeNotifs.ID_GROUP_ACCEPTED);
|
||||
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]}}}};
|
||||
|
||||
@@ -327,21 +327,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
// tools.mylog('rec', rec);
|
||||
}).then((myrec) => {
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
||||
// nuovo Record:
|
||||
// aggiungi il creatore al gruppo stesso
|
||||
return User.setGroupsCmd(mydata.idapp, req.user.username,
|
||||
myrec.groupname,
|
||||
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
|
||||
return res.send(myrec);
|
||||
});
|
||||
}
|
||||
}).then(async (myrec) => {
|
||||
|
||||
let setnotif = false;
|
||||
let typedir = 0;
|
||||
let typeid = 0;
|
||||
let groupNameDest = '';
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
||||
@@ -358,13 +349,25 @@ 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 : '';
|
||||
setnotif = true;
|
||||
}
|
||||
|
||||
if (setnotif) {
|
||||
SendNotif.createNewNotification(req, res, params.table, myrec, typedir, typeid);
|
||||
await SendNotif.createNewNotification(req, res, {groupNameDest}, params.table, myrec, typedir, typeid);
|
||||
}
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
||||
// nuovo Record:
|
||||
// aggiungi il creatore al gruppo stesso
|
||||
return User.setGroupsCmd(mydata.idapp, req.user.username,
|
||||
myrec.groupname,
|
||||
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
|
||||
return res.send(myrec);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return res.send(myrec);
|
||||
}).catch((e) => {
|
||||
console.error('settable', e.message);
|
||||
|
||||
@@ -44,7 +44,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
}).then(async (recmyevent) => {
|
||||
// tools.mylog('myevent:', myevent);
|
||||
// tools.mylog('already exist');
|
||||
SendNotif.createNewNotification(req, res, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
|
||||
SendNotif.createNewNotification(req, res, {}, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
|
||||
return res;
|
||||
}).then((res) => {
|
||||
res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
|
||||
@@ -59,7 +59,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
myevent.findById(idobj).then((recmyevent) => {
|
||||
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
|
||||
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC
|
||||
SendNotif.createNewNotification(req, res, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
|
||||
SendNotif.createNewNotification(req, res, {}, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
|
||||
return res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
|
||||
});
|
||||
});
|
||||
@@ -79,7 +79,7 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
if (notify === '1') {
|
||||
SendNotif.createNewNotification(req, res, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC);
|
||||
SendNotif.createNewNotification(req, res, {}, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC);
|
||||
}
|
||||
|
||||
tools.mylog('DELETED ', recmyevent.descr, recmyevent._id);
|
||||
|
||||
@@ -29,8 +29,16 @@ async function getGroupRecAdminsInfo(idapp, data) {
|
||||
router.post('/load', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const groupname = req.body.groupname;
|
||||
const usernameOrig = req.user.username;
|
||||
|
||||
try {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
||||
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
||||
|
||||
const whatshow = MyGroup.getWhatToShow(idapp, req.user.username);
|
||||
let data = await MyGroup.findOne({idapp, groupname}, whatshow).lean();
|
||||
|
||||
|
||||
@@ -295,6 +295,12 @@ module.exports = {
|
||||
STATUS_GROUPS_REFUSED: 4,
|
||||
},
|
||||
|
||||
GroupsNotifs: {
|
||||
STATUS_GROUPS_NEW: 1,
|
||||
STATUS_GROUPS_ACCEPTED: 2,
|
||||
STATUS_GROUPS_REFUSED: 4,
|
||||
},
|
||||
|
||||
TypeNotifs: {
|
||||
TYPEDIR_BACHECA: 1,
|
||||
ID_BACHECA_NEW_GOOD: 1,
|
||||
@@ -307,13 +313,13 @@ module.exports = {
|
||||
TYPEDIR_FRIENDS: 3,
|
||||
ID_FRIENDS_NEW_REC: 1,
|
||||
ID_FRIENDS_ACCEPTED: 2,
|
||||
ID_FRIENDS_REFUSED: 3,
|
||||
ID_FRIENDS_ACCEPTED_MY_REQUEST: 4,
|
||||
ID_FRIENDS_REFUSED: 4,
|
||||
ID_FRIENDS_ACCEPTED_MY_REQUEST: 8,
|
||||
|
||||
TYPEDIR_GROUPS: 4,
|
||||
ID_GROUP_NEW_REC: 1,
|
||||
ID_GROUP_ACCEPTED: 2,
|
||||
ID_GROUP_REFUSED: 3,
|
||||
ID_GROUP_REFUSED: 4,
|
||||
|
||||
TYPEDIR_CIRCUITS: 5,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user