diff --git a/src/server/locales/it.json b/src/server/locales/it.json index 0916263..259fcfe 100644 --- a/src/server/locales/it.json +++ b/src/server/locales/it.json @@ -3,10 +3,10 @@ "Hello %s": "Ciao %s", "Good: %s": "Bene: %s", "Service: %s": "Servizio: %s", - "NEW_GOOD": "%s ha aggiunto un nuovo Bene: %s", - "NEW_SERVICE": "%s ha aggiunto un nuovo Servizio: %s", - "NEW_HOSP": "%s ha aggiunto una nuova Ospitalità: %s", - "NEW_EVENT": "%s ha aggiunto un nuovo Evento: %s", + "NEW_GOOD": "❇️ %s ha aggiunto un nuovo Bene: \n%s", + "NEW_SERVICE": "❇️ %s ha aggiunto un nuovo Servizio: \n%s", + "NEW_HOSP": "❇️ %s ha aggiunto una nuova Ospitalità: \n%s", + "NEW_EVENT": "❇️ %s ha aggiunto un nuovo Evento: \n%s", "OPEN PAGE": "APRI la APP RISO oppure visita riso.app", "%s asked you for Friendship": "%s ti ha chiesto l'Amicizia", "%s accepted your Friendship": "%s ha accettato l'Amicizia", diff --git a/src/server/models/city.js b/src/server/models/city.js index a3eae1c..d58edf6 100755 --- a/src/server/models/city.js +++ b/src/server/models/city.js @@ -77,6 +77,17 @@ CitySchema.statics.getProvinceByIdCity = async function(idcity) { return ''; } +CitySchema.statics.getCircuitNameBystrProv = async function(strProv) { + const { Circuit } = require('../models/circuit'); + + const myrec = await Circuit.findOne({strProv}).lean(); + if (myrec) { + return myrec.name; + } + + return ''; +} + CitySchema.statics.getRegionByIdCity = async function(idcity) { const myrec = await City.findOne({_id: idcity}).lean(); if (myrec) { diff --git a/src/server/models/sendnotif.js b/src/server/models/sendnotif.js index 8ddce1a..5ce9585 100755 --- a/src/server/models/sendnotif.js +++ b/src/server/models/sendnotif.js @@ -197,6 +197,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec; tag = 'newhosp'; } + recnotif.textaddTelegram = 'Vedi annuncio'; } else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) { recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec; tag = 'newevent'; @@ -928,6 +929,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, // Send only to the destination to reach: const userlist = await User.find({ idapp: myrecnotifpass.idapp, + // username: 'SuryaArena2', //TOGLIERE $or: [ { deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], @@ -938,6 +940,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, lang: 1, username: 1, 'profile.notifs': 1, + 'profile.mycircuits': 1, 'profile.resid_province': 1, 'profile.notif_idCities': 1, 'profile.notif_provinces': 1, @@ -946,6 +949,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, 'profile.notif_sector_goods': 1, }).lean(); + let arrcircuits = []; let arrprovinces = []; let arrregions = []; let idSector = 0; @@ -959,10 +963,13 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean(); if (myrectableorig) { for (const city of myrectableorig.idCity) { + const prov = await City.getProvinceByIdCity(city); arrprovinces.push(await City.getProvinceByIdCity(city)); arrregions.push(await City.getRegionByIdCity(city)); + arrcircuits.push(await City.getCircuitNameBystrProv(prov)); } + if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) { idSector = myrectableorig.idSectorGood; } else { @@ -979,6 +986,8 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, for (const user of userlist) { + const mycircuits = user.profile.mycircuits; + if (user.profile && user.profile.notifs) { const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotifpass.typedir); @@ -1017,6 +1026,11 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, send = true; } + if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_MY_RIS_CIRCUIT) && + user.profile.mycircuits && user.profile.mycircuits.some(r => arrcircuits.indexOf(r.circuitname) >= 0)) { + send = true; + } + if (idSector && usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_SECTOR)) { // Controlla se è del settore selezionato if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) { @@ -1040,7 +1054,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, if (send) { let myrecnotif = new SendNotif(myrecnotifpass); myrecnotif.dest = user.username; - return await SendNotif.saveAndSendNotif(myrecnotif, req, res, user); + await SendNotif.saveAndSendNotif(myrecnotif, req, res, user); } } }