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) {
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 }});

View File

@@ -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...');
}
}
}
}