favorite: send if alert active
This commit is contained in:
@@ -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 }});
|
||||||
|
|||||||
@@ -370,6 +370,7 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
username: 1,
|
username: 1,
|
||||||
'profile.teleg_id': 1,
|
'profile.teleg_id': 1,
|
||||||
|
'profile.notifs': 1,
|
||||||
},
|
},
|
||||||
).lean();
|
).lean();
|
||||||
|
|
||||||
@@ -379,41 +380,55 @@ 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;
|
||||||
|
|
||||||
if (params.sendreally) {
|
let sendmsg = false;
|
||||||
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 => {
|
|
||||||
|
|
||||||
}).
|
if (params.typenotif === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
|
||||||
catch(e => {
|
if (!usernotifprofile || (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED))) {
|
||||||
console.error(e.message);
|
sendmsg = true;
|
||||||
});
|
}
|
||||||
|
} else {
|
||||||
|
sendmsg = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (sendmsg) {
|
||||||
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) {
|
if (params.sendreally) {
|
||||||
const telegid = user.profile.teleg_id;
|
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) {
|
catch(e => {
|
||||||
risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text);
|
console.error(e.message);
|
||||||
await tools.snooze(50);
|
});
|
||||||
|
|
||||||
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++;
|
numrec++;
|
||||||
if (params.sendreally && risult) {
|
if (params.sendreally && risult) {
|
||||||
nummsgsent++;
|
nummsgsent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nummsgsent > 0 && (nummsgsent % 100) === 0) {
|
if (nummsgsent > 0 && (nummsgsent % 100) === 0) {
|
||||||
console.log('Inviati ', nummsgsent, 'messaggi...');
|
console.log('Inviati ', nummsgsent, 'messaggi...');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user