favorite: send if alert active

This commit is contained in:
Surya Paolo
2023-04-12 16:29:22 +02:00
parent f13786fca1
commit cada7aa0b6
2 changed files with 41 additions and 26 deletions

View File

@@ -4809,7 +4809,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
UserSchema.statics.updateVersion = async function (userversion, recUser) { UserSchema.statics.updateVersion = async function (userversion, recUser) {
if (userversion < 063) { if (userversion < 603) {
recUser.profile.notifs.push( { dir: 11, value: 1 }) recUser.profile.notifs.push( { dir: 11, value: 1 })
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }}); await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }});

View File

@@ -370,6 +370,7 @@ module.exports = {
{ {
username: 1, username: 1,
'profile.teleg_id': 1, 'profile.teleg_id': 1,
'profile.notifs': 1,
}, },
).lean(); ).lean();
@@ -379,8 +380,21 @@ module.exports = {
const mytitle = await tools.convertSpecialTags(user, params.title); const mytitle = await tools.convertSpecialTags(user, params.title);
const mycontent = await tools.convertSpecialTags(user, params.content); const mycontent = await tools.convertSpecialTags(user, params.content);
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === params.typenotif);
let risult = null; let risult = null;
let sendmsg = false;
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 (sendmsg) {
if (params.sendreally) { if (params.sendreally) {
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.PUSH_NOTIFICATION)) { if (tools.isBitActive(params.typesend, shared_consts.TypeSend.PUSH_NOTIFICATION)) {
const myparam = { ...params }; const myparam = { ...params };
@@ -417,6 +431,7 @@ module.exports = {
} }
} }
} }
}
if (nummsgsent > 0) { if (nummsgsent > 0) {
console.log('FINE Invio Messaggi ! Inviati Totali: ', nummsgsent, 'su', numrec); console.log('FINE Invio Messaggi ! Inviati Totali: ', nummsgsent, 'su', numrec);