diff --git a/src/server/locales/it.json b/src/server/locales/it.json index a6cb5aa..77fe052 100644 --- a/src/server/locales/it.json +++ b/src/server/locales/it.json @@ -3,8 +3,9 @@ "Hello %s": "Ciao %s", "Good: %s": "Bene: %s", "Service: %s": "Servizio: %s", - "%s new Good: %s": "%s nuovo Bene: %s", - "%s new Service: %s": "%s nuovo 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", "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/search.js b/src/server/models/search.js new file mode 100755 index 0000000..b39fb5d --- /dev/null +++ b/src/server/models/search.js @@ -0,0 +1,45 @@ +const mongoose = require('mongoose').set('debug', false) +const Schema = mongoose.Schema; + +mongoose.Promise = global.Promise; +mongoose.level = "F"; + +const tools = require('../tools/general'); + +const { ObjectID } = require('mongodb'); + +// Resolving error Unknown modifier: $pushAll +mongoose.plugin(schema => { + schema.options.usePushEach = true +}); + +const searchSchema = new Schema({ + idapp: { + type: String, + }, + userId: { + type: String, + }, + text: { + type: String, + }, +}); + +searchSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) { + const Search = this; + + let myfind = {}; + if (sall === '1') + myfind = { idapp }; + else + myfind = { userId, idapp }; + + return Search.find(myfind, (err, arrsearch) => { + return arrsearch + }); +}; + + +const Search = mongoose.model('Search', searchSchema); + +module.exports = { Search }; diff --git a/src/server/models/sendnotif.js b/src/server/models/sendnotif.js index cd2479a..cac8b7f 100755 --- a/src/server/models/sendnotif.js +++ b/src/server/models/sendnotif.js @@ -182,14 +182,19 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) { if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) { - newdescr = i18n.__('%s new Good: %s', userorig, mydescr); + newdescr = i18n.__('NEW_GOOD', userorig, mydescr); recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYGOODS, true) + myidrec; tag = 'newgood'; } else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) { - newdescr = i18n.__('%s new Service: %s', userorig, mydescr); + newdescr = i18n.__('NEW_SERVICE', userorig, mydescr); recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYSKILLS, true) + myidrec; tag = 'newservice'; + } else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP) { + newdescr = i18n.__('NEW_HOSP', userorig, mydescr); + recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec; + tag = 'newhosp'; } + recnotif.textaddTelegram = 'Vedi post'; } else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) { recnotif.openUrl = '/my/' + sender; if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) { @@ -882,6 +887,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, lang: 1, username: 1, 'profile.notifs': 1, + 'profile.resid_province': 1, 'profile.notif_idCities': 1, 'profile.notif_provinces': 1, 'profile.notif_regions': 1, @@ -939,6 +945,10 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) { // Estrai la Città, la Provincia e la regione. + if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE) && + user.profile.resid_province && arrprovinces.indexOf(user.profile.resid_province) >= 0) { + send = true; + } if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) && user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) { send = true; diff --git a/src/server/models/user.js b/src/server/models/user.js index 7182cc2..5c8799e 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -4696,13 +4696,21 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v try { - try { - if (recUserSave && recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) { - recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER; - await recUserSave.save(); + if (version) { + let versattualeuser = 0; + if (!recUser.profile.version) { + recUser.version = 0; + versattualeuser = 0; + } else { + versattualeuser = recUser.profile.version; + } + + if (versattualeuser < version) { + // Aggiornamento versione + recUser = await User.updateVersion(versattualeuser, recUser); + + await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }}); } - } catch (e) { - console.error('Err addExtraInfo notifs ', e); } const listSentMyRequestFriends = await User.find({ @@ -4781,23 +4789,6 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id); - if (version) { - let versattualeuser = 0; - if (!recUser.profile.version) { - recUser.version = 0; - versattualeuser = 0; - } else { - versattualeuser = recUser.profile.version; - } - - if (versattualeuser < version) { - // Aggiornamento versione - recUser = await User.updateVersion(versattualeuser, recUser); - - await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }}); - } - } - return recUser; } catch (e) { @@ -4808,9 +4799,48 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v }; UserSchema.statics.updateVersion = async function (userversion, recUser) { + + const { MySkill } = require('../models/myskill'); + const { MyGood } = require('../models/mygood'); + const { City } = require('../models/city'); - if (userversion < 603) { - recUser.profile.notifs.push( { dir: 11, value: 1 }) + if (userversion < 604) { + if (!recUser.profile.notifs || recUser.profile.notifs.length === 0) { + recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER; + } + + const recfavoriteNotif = recUser.profile.notifs.find((rec) => rec.dir === 11); + if (!recfavoriteNotif){ + recUser.profile.notifs.push( { dir: 11, value: 1 }) + } + + // Imposta la provincia, se non l'ho messa, in base al bene o servizio che hai messo. + if (!recUser.profile.resid_province) { + let resid_province = ''; + const firstrec = await MySkill.findOne({userId: recUser._id}).lean(); + if (firstrec && firstrec.idCity && firstrec.idCity.length > 0) { + resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]); + } else { + const firstrec = await MyGood.findOne({userId: recUser._id}).lean(); + if (firstrec && firstrec.idCity && firstrec.idCity.length === 1) { + resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]); + } + } + + + if (resid_province) { + await User.findOneAndUpdate({_id: recUser._id}, {$set: {'profile.resid_province': resid_province}}); + } + } + + let recmybach = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_BACHECA); + if (!tools.isBitActive(recmybach.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE)) { + recmybach.value = tools.SetBit(recmybach.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE); + for (let i = 0; i < recUser.profile.notifs.length; i++) { + if (recUser.profile.notifs[i].dir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) + recUser.profile.notifs[i].value = recmybach.value; + } + } await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }}); } diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index cf081d7..1414e9b 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -448,9 +448,12 @@ router.post('/settable', authenticate, async (req, res) => { if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) { typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA; - typeid = (params.table === shared_consts.TABLES_MYGOODS) - ? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD - : shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE; + if (params.table === shared_consts.TABLES_MYGOODS) + typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD + else if (params.table === shared_consts.TABLES_MYSKILLS) + typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE + else if (params.table === shared_consts.TABLES_MYHOSPS) + typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP setnotif = true; } diff --git a/src/server/tools/general.js b/src/server/tools/general.js index c13b2b7..9b9d7c5 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -1992,6 +1992,9 @@ module.exports = { getQueryTable: async function (idapp, params, user) { + + const { Search }= require('../models/search'); + if (typeof params.startRow !== 'number') { throw new Error('startRow must be number'); } else if (typeof params.endRow !== 'number') { @@ -2571,6 +2574,12 @@ module.exports = { if (querytemp) { query = [...query, ...querytemp]; } + + // Save the search: + if (user._id) { + const mysearch = new Search({idapp, userId: user._id, text: params.filter}); + await mysearch.save(); + } } if (params.table === 'mygroups' || params.table === 'circuits') { @@ -2718,8 +2727,9 @@ module.exports = { }, SetBit(myval, bit) { - myval = myval & bit; - return myval; + let myvalout = myval + myvalout |= bit + return myvalout }, async snooze(ms) { diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js index a7ae73e..226821a 100755 --- a/src/server/tools/shared_nodejs.js +++ b/src/server/tools/shared_nodejs.js @@ -362,6 +362,7 @@ module.exports = { NEW_ADV_MY_GROUPS: 8, NEW_ADV_MY_RIS_CIRCUIT: 16, NEW_ADV_SECTOR: 32, + NEW_ADV_YOUR_PROVINCE: 64, }, StatusNotifs: { @@ -404,6 +405,7 @@ module.exports = { TYPEDIR_BACHECA: 1, ID_BACHECA_NEW_GOOD: 1, ID_BACHECA_NEW_SERVICE: 2, + ID_BACHECA_NEW_HOSP: 4, TYPEDIR_EVENTS: 2, ID_EVENTS_NEW_REC: 1, @@ -513,7 +515,7 @@ module.exports = { DEFAULT_NOTIFS_USER: [ { 'dir': 1, - 'value': 24 + 'value': 88 }, { 'dir': 2,