diff --git a/src/server/models/user.js b/src/server/models/user.js index 5e4cce8..7182cc2 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -4809,7 +4809,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v UserSchema.statics.updateVersion = async function (userversion, recUser) { - if (userversion < 063) { + if (userversion < 603) { recUser.profile.notifs.push( { dir: 11, value: 1 }) await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }}); diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js index 6a5a2d6..2238a7a 100755 --- a/src/server/tools/globalTables.js +++ b/src/server/tools/globalTables.js @@ -370,6 +370,7 @@ module.exports = { { username: 1, 'profile.teleg_id': 1, + 'profile.notifs': 1, }, ).lean(); @@ -379,41 +380,55 @@ module.exports = { const mytitle = await tools.convertSpecialTags(user, params.title); const mycontent = await tools.convertSpecialTags(user, params.content); + const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === params.typenotif); + let risult = null; - if (params.sendreally) { - if (tools.isBitActive(params.typesend, shared_consts.TypeSend.PUSH_NOTIFICATION)) { - const myparam = { ...params }; - risult = await tools.sendNotificationToUser(user._id, mytitle, mycontent, myparam.openUrl, myparam.openUrl2, myparam.tag, - myparam.actions, myparam.id). - then(ris => { + let sendmsg = false; - }). - catch(e => { - console.error(e.message); - }); + if (params.typenotif === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) { + if (!usernotifprofile || (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED))) { + sendmsg = true; + } + } else { + sendmsg = true; + } - } - if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) { - const telegid = user.profile.teleg_id; + if (sendmsg) { + if (params.sendreally) { + if (tools.isBitActive(params.typesend, shared_consts.TypeSend.PUSH_NOTIFICATION)) { + const myparam = { ...params }; + risult = await tools.sendNotificationToUser(user._id, mytitle, mycontent, myparam.openUrl, myparam.openUrl2, myparam.tag, + myparam.actions, myparam.id). + then(ris => { - text = tools.getContentNotifByParams(params, mycontent, shared_consts.TypeSend.TELEGRAM); - if (telegid > 0) { - risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text); - await tools.snooze(50); + }). + catch(e => { + console.error(e.message); + }); - textsent = risult.text; + } + if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) { + const telegid = user.profile.teleg_id; + + text = tools.getContentNotifByParams(params, mycontent, shared_consts.TypeSend.TELEGRAM); + if (telegid > 0) { + risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text); + await tools.snooze(50); + + textsent = risult.text; + } } } - } - numrec++; - if (params.sendreally && risult) { - nummsgsent++; - } + numrec++; + if (params.sendreally && risult) { + nummsgsent++; + } - if (nummsgsent > 0 && (nummsgsent % 100) === 0) { - console.log('Inviati ', nummsgsent, 'messaggi...'); + if (nummsgsent > 0 && (nummsgsent % 100) === 0) { + console.log('Inviati ', nummsgsent, 'messaggi...'); + } } } }