Notifications

Settings Notifications
User Panel
This commit is contained in:
Paolo Arena
2022-07-23 17:48:33 +02:00
parent e9ce597027
commit b06f1e4ab8
19 changed files with 472 additions and 121 deletions

View File

@@ -574,13 +574,17 @@ module.exports = {
'type',
'userId',
'sender',
'typedir',
'typeid',
'dest',
'descr',
'link',
'openUrl',
'datenotif',
'read',
'deleted',
'idapp',
'tablerec',
'idrec',
'status'];
},
@@ -723,7 +727,7 @@ module.exports = {
};
// Pass object into sendNotification
return webpush.sendNotification(subscription, JSON.stringify(payload),
return webpush.sendNotification(subscription._doc, JSON.stringify(payload),
pushOptions).
catch(err => {
if (err.statusCode === 410) {
@@ -734,7 +738,7 @@ module.exports = {
}
}).
then(ris => {
// console.log('ris', ris)
console.log('sendNotification', ris)
}).
catch(err => {
console.error(err);
@@ -1141,8 +1145,7 @@ module.exports = {
getNomeAppByIdApp: function(idapp) {
const myapp =
this.getApps().find(item => item.idapp === idapp);
const myapp = this.MYAPPS.find(item => item.idapp === idapp);
if (myapp)
return ((process.env.NODE_ENV === 'test') ? 'Test: ' : '') + myapp.name;
else
@@ -1161,7 +1164,7 @@ module.exports = {
getHostByIdApp: function(idapp) {
const myapp = this.getApps().find(item => item.idapp === idapp);
const myapp = this.MYAPPS.find(item => item.idapp === idapp);
if (myapp) {
let siteport = (myapp.portapp && myapp.portapp !== '0') ? (':' +
myapp.portapp) : '';
@@ -1185,7 +1188,7 @@ module.exports = {
getConfSiteOptionEnabledByIdApp: function(idapp, option) {
const myapp = this.getApps().find(item => item.idapp === idapp);
const myapp = this.MYAPPS.find(item => item.idapp === idapp);
if (myapp) {
if (myapp.hasOwnProperty('confsite')) {
@@ -1200,7 +1203,7 @@ module.exports = {
getConfParamSiteByIdApp: function(idapp, field) {
const myapp = this.getApps().find(item => item.idapp === idapp);
const myapp = this.MYAPPS.find(item => item.idapp === idapp);
if (myapp) {
if (myapp.hasOwnProperty('confsite')) {
@@ -1214,7 +1217,7 @@ module.exports = {
},
isAbilitaNave: function(idapp) {
const myapp = this.getApps().find(item => item.idapp === idapp);
const myapp = this.MYAPPS.find(item => item.idapp === idapp);
return myapp.abilitanave;
},
@@ -1222,7 +1225,7 @@ module.exports = {
let mypath = '';
const myapp =
this.getApps().find(item => item.idapp === idapp);
this.MYAPPS.find(item => item.idapp === idapp);
if (myapp) {
if (process.env.NODE_ENV === 'test')
mypath = (myapp) ? myapp.dir_test : '';
@@ -1240,7 +1243,7 @@ module.exports = {
},
getAdminEmailByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
if (myapp)
return myapp.adminemail;
else
@@ -1248,7 +1251,7 @@ module.exports = {
},
getreplyToEmailByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
if (myapp)
return myapp.replyTo;
else
@@ -1256,7 +1259,7 @@ module.exports = {
},
getpathregByIdApp: function(idapp, lang) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
if (myapp) {
const addstr = myapp.pathreg_add ? myapp.pathreg_add : '';
@@ -1276,7 +1279,7 @@ module.exports = {
},
getManagerEmailByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
if (myapp)
return !!myapp.manageremail ? myapp.manageremail : '';
else
@@ -1284,17 +1287,17 @@ module.exports = {
},
getEmailByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
return (myapp) ? myapp.email_from : '';
},
getPwdByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
return (myapp) ? this.decryptdata(myapp.email_pwd) : '';
},
getTelegramBotNameByIdApp: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
if (process.env.NODE_ENV === 'test')
return (myapp) ? myapp.telegram_bot_name_test : '';
else
@@ -1303,7 +1306,7 @@ module.exports = {
getTelegramSupportChat: function(idapp) {
try {
const myapp = this.getApps().find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
return (myapp && myapp.telegram_support_chat)
? myapp.telegram_support_chat
: '';
@@ -1313,8 +1316,7 @@ module.exports = {
},
getTelegramKeyByIdApp: function(idapp) {
const myarr = this.getApps();
const myapp = myarr.find((item) => item.idapp === idapp);
const myapp = this.MYAPPS.find((item) => item.idapp === idapp);
if (process.env.NODE_ENV === 'test')
return (myapp) ? myapp.telegram_key_test : '';
else
@@ -2750,12 +2752,16 @@ module.exports = {
},
async loadApps() {
this.MYAPPS = await Site.findAll(0);
// console.log('this.MYAPPS', this.MYAPPS);
try {
this.MYAPPS = await Site.findAll(0);
console.log('this.MYAPPS', this.MYAPPS);
}catch (e) {
console.error('loadApps', e);
}
},
getApps() {
async getApps() {
if (this.MYAPPS.length <= 0)
this.loadApps();
await this.loadApps();
return this.MYAPPS;
},
@@ -2936,6 +2942,8 @@ module.exports = {
},
updateQueryStringParameter(uri, key, value) {
if (uri === '')
return '';
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {

View File

@@ -74,7 +74,6 @@ const tools = require('./general');
const shared_consts = require('./shared_nodejs');
const sendemail = require('../sendemail');
module.exports = {
@@ -217,46 +216,60 @@ module.exports = {
return process.env.ENABLE_PUSHNOTIFICATION === '1';
},
async sendNotif(res, idapp, user, recnotif, cmd) {
async sendNotif(typenotif, idnotif, res, idapp, user, recnotif, cmd) {
// Controlla nelle impostazioni che tipo di Notifica visualizzare
if (tools.isBitActive(recnotif.options, shared_consts.MessageOptions.Notify_ByPushNotification)) {
if (this.checkifSendPushNotification) {
console.log('SEND PUSH NOTIFICATION ');
const sendemail = require('../sendemail');
const params = {
sendreally: true,
typesend: shared_consts.TypeSend.PUSH_NOTIFICATION,
title: this.getNomeAppByIdApp(idapp),
content: recnotif.descr ? recnotif.descr : tools.getContentByTypeMsg(recnotif.typemsg),
openUrl: tools.updateQueryStringParameter(recnotif.link, 'idnotif', recnotif._id),
typemsg: recnotif.typemsg ? recnotif.typemsg : shared_consts.TypeMsg.SEND_TO_USER,
}
ris = await this.SendMsgToParam(idapp, params);
recnotif.link = mylink;
try {
if (!recnotif.options) {
recnotif.options = shared_consts.MessageOptions.Notify_ByPushNotification;
}
if (tools.isBitActive(recnotif.options, shared_consts.MessageOptions.Notify_ByPushNotification)) {
if (this.checkifSendPushNotification) {
const params = {
sendreally: true,
typesend: shared_consts.TypeSend.PUSH_NOTIFICATION + shared_consts.TypeSend.TELEGRAM,
title: tools.getNomeAppByIdApp(idapp),
content: recnotif.descr ? recnotif.descr : tools.getContentByTypeMsg(recnotif.typemsg),
openUrl: tools.updateQueryStringParameter(recnotif.openUrl, 'idnotif', recnotif._id),
typemsg: recnotif.typemsg ? recnotif.typemsg : shared_consts.TypeMsg.SEND_TO_USER,
typenotif,
idnotif,
usernameDest: recnotif.usernameDest ? recnotif.usernameDest : recnotif.dest,
};
ris = await this.SendMsgToParam(idapp, params);
}
}
// Send Msg by EMAIL
if (tools.isBitActive(recnotif.options, shared_consts.MessageOptions.Notify_ByEmail)) {
// Read from the operator table first
let emaildest = await Operator.getEmailByUsername(recnotif.dest.idapp, recnotif.dest.username);
if (!emaildest)
emaildest = await User.getEmailByUsername(recnotif.dest.idapp, recnotif.dest.username);
console.log('emaildest', emaildest);
await sendemail.sendEmail_Msg(res, user.lang, emaildest, user, idapp, recnotif);
}
return true;
} catch (e) {
console.error('sendNotif', e, typenotif, recnotif);
return false;
}
// Send Msg by EMAIL
if (emaildest && tools.isBitActive(recnotif.options, shared_consts.MessageOptions.Notify_ByEmail)) {
// Read from the operator table first
let emaildest = await Operator.getEmailByUsername(recnotif.dest.idapp, recnotif.dest.username);
if (!emaildest)
emaildest = await User.getEmailByUsername(recnotif.dest.idapp, recnotif.dest.username);
console.log('emaildest', emaildest);
await sendemail.sendEmail_Msg(res, user.lang, emaildest, user, idapp, recnotif);
}
return true;
},
SendMsgToParam: async function(idapp, params) {
try {
console.log('SendMsgToParam');
const telegrambot = require('../telegram/telegrambot');
if (params.typesend === 0)
@@ -343,7 +356,8 @@ module.exports = {
console.error(e.message);
});
} else if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) {
}
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) {
const telegid = user.profile.teleg_id;
if (telegid > 0) {

View File

@@ -108,6 +108,9 @@ module.exports = {
TABLES_VISU_STAT_IN_HOME: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'mygroups'],
TABLES_ADV_NOTIFICATION: ['myskills', 'myhosps', 'mygoods'],
TABLES_EVENTS_NOTIFICATION: ['mybachecas'],
TABLES_ID_NUMBER: [
'permissions',
'levels',
@@ -273,8 +276,38 @@ module.exports = {
PUSH_NOTIFICATION: 1,
TELEGRAM: 2,
},
UsersNotif: {
NEW_ADV_CITY: 1,
NEW_ADV_PROVINCE: 2,
NEW_ADV_REGION: 4,
NEW_ADV_MY_GROUPS: 8,
NEW_ADV_MY_RIS_CIRCUIT: 16,
NEW_ADV_SECTOR: 32,
},
TypeNotifs: {
TYPEDIR_BACHECA: 1,
ID_BACHECA_NEW_GOOD: 1,
ID_BACHECA_NEW_SERVICE: 2,
TYPEDIR_EVENTS: 2,
ID_EVENTS_NEW_REC: 1,
ID_EVENTS_REMOVE_REC: 2,
TYPEDIR_FRIENDS: 3,
ID_FRIENDS_NEW_REC: 1,
TYPEDIR_CIRCUITS: 4,
TYPEDIR_BOOKING: 5,
TYPEDIR_MSGS: 6,
ID_MSGS_NEW_REC: 1,
},
// Tipi di Notifiche:
/*
Notif: {
UPDATE_APP: 1,
NEW_GOOD_MY_PROVINCE: 12,
@@ -292,6 +325,8 @@ module.exports = {
RIS_SENT_REFUSED: 52,
},
*/
fieldsUserToChange() {
return [