Notifications
Settings Notifications User Panel
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user