Notification with Service Workers now is working!

When a Notification arrives, it save into the IndexDb,
then in Vue.js call a polling to check in the db if there is a different record count.
If is different then call a get to update the notification.
This commit is contained in:
paoloar77
2022-08-07 02:01:35 +02:00
parent 8a587dc715
commit e433d3db8c
8 changed files with 76 additions and 41 deletions

View File

@@ -583,6 +583,8 @@ module.exports = {
'idapp',
'tablerec',
'extrafield',
'tag',
'options',
'idrec',
'status'];
},
@@ -744,7 +746,9 @@ module.exports = {
});
},
sendNotificationToUser: function(userId, title, content, openUrl, openUrl2, tag, actions) {
sendNotificationToUser: function(userId, title, content, openUrl, openUrl2, tag, actions, id) {
content = this.convertHTMLtoText(content);
let payload = {
actions,
@@ -753,6 +757,7 @@ module.exports = {
url: openUrl,
url2: openUrl2,
tag,
id,
// ttl: req.body.ttl,
// icon: req.body.icon,
// image: req.body.image,
@@ -931,7 +936,8 @@ module.exports = {
}
},
sendNotifGroupByUsername: async function(cmd, typeid_pass, idapp, usernameOrig, usernameDest, username_action, groupname, myrecgroup, isAdmin, username_worked) {
sendNotifGroupByUsername: async function(
cmd, typeid_pass, idapp, usernameOrig, usernameDest, username_action, groupname, myrecgroup, isAdmin, username_worked) {
const {SendNotif} = require('../models/sendnotif');
const {User} = require('../models/user');
@@ -976,7 +982,8 @@ module.exports = {
typeid = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_GRUPPO, myuserdata, usernameDest, groupname, myrecgroup._id);
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_GRUPPO, myuserdata, usernameDest, groupname,
myrecgroup._id);
onlysave = false;
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_USER) {
typeid = shared_consts.TypeNotifs.ID_GROUP_BLOCK_USER;
@@ -1002,7 +1009,6 @@ module.exports = {
const {MyGroup} = require('../models/mygroup');
const {User} = require('../models/user');
const group = await MyGroup.findOne({idapp, groupname}, {_id: 1, admins: 1, createdBy: 1}).lean();
if (!group)
return;
@@ -1138,6 +1144,10 @@ module.exports = {
convertHTMLtoText(myhtml) {
let msg = myhtml;
msg = msg.replace('"', '"');
msg = msg.replace(/<strong>/g, '');
msg = msg.replace(/<\/strong>/g, '');
msg = msg.replace(/<em>/g, '');
msg = msg.replace(/<\/em>/g, '');
msg = msg.replace('&gt;', '>');
msg = msg.replace('&lt;', '<');
msg = msg.replace('&amp;', '&');
@@ -1547,12 +1557,10 @@ module.exports = {
});
// Iscritti Conacreis
if (params.filterand.includes(shared_consts.FILTER_MISSING_PAYMENT))
filtriadded.push({
$or: [
{ha_pagato: {$exists: false}},
{ha_pagato: {$exists: true, $lt: 1}}],
});
if (params.filterand.includes(shared_consts.FILTER_REPORTED))
filtriadded.push(
{reported: {$exists: true, $eq: true}},
);
if (params.filterand.includes(
shared_consts.FILTER_TO_MAKE_MEMBERSHIP_CARD))
@@ -1855,6 +1863,17 @@ module.exports = {
const [ris] = await mythistable.aggregate(query);
if (ris) {
if (params.table === 'users') {
for (const myrec of ris.rows) {
myrec.password = '**********';
}
} else if (params.table === 'mygroups') {
for (const myrec of ris.rows) {
if (myrec.pwd_cryp)
myrec.pwd_cryp = '**********';
}
}
// console.table(ris.rows);
// console.log('ROW ', ris.count);
return ({count: ris.count, rows: ris.rows});