- Versione 1.0.28

- Bottone "Condividi" permette di creare un post Telegram con l'annuncio selezionato.
- migliorata grafica dell'annuncio.
This commit is contained in:
Surya Paolo
2024-02-27 22:08:06 +01:00
parent 3191312372
commit 6ff9922a29
6 changed files with 402 additions and 38 deletions

View File

@@ -21,6 +21,11 @@ const shared_consts = require('./shared_nodejs');
const mongoose = require('mongoose').set('debug', false);
const Subscription = require('../models/subscribers');
const { Contribtype } = require('../models/contribtype');
const { Skill } = require('../models/skill');
const { Good } = require('../models/good');
const { SectorGood } = require('../models/sectorgood');
const server_constants = require('./server_constants');
const download = require('image-downloader');
@@ -29,6 +34,7 @@ const download = require('image-downloader');
const webpush = require('web-push');
const i18n = require('i18n');
const { StatusSkill } = require('../models/statusSkill');
const FILELOG = 'filelog.txt';
@@ -418,6 +424,8 @@ module.exports = {
FIOREDELLAVITA: '15',
PIUCHEBUONO: '17',
IDAPP_BOTONGROUP: '1000',
HELP_CHAT: '',
TYPECONF_ZOOM: 'zoom',
TYPECONF_JITSI: 'jitsi',
@@ -2904,7 +2912,7 @@ module.exports = {
$match: {
$or: [
{ $and: params.filtersearch3and },
{ idStatusSkill: { $in: [2]} }
{ idStatusSkill: { $in: [2] } }
]
}
});
@@ -4238,13 +4246,22 @@ module.exports = {
return myval.charAt(0).toUpperCase() + myval.slice(1);
},
firstchars(value, numchars = 200) {
firstchars(value, numchars = 200, continua, link) {
if (!value) {
return '';
}
try {
let mycar = value.substring(0, numchars);
if (value.length > numchars) mycar += '...';
if (value.length > numchars) {
if (continua) {
if (link)
mycar += `<em> (... <a href="${link}">continua sulla App</a>)</em>`;
else
mycar += `<em> (... continua sulla App)</em>`;
} else {
mycar += ' ...';
}
}
return mycar;
} catch (e) {
return value;
@@ -4307,21 +4324,6 @@ module.exports = {
return `<a href='${link}'>${username}</a>`;
},
firstchars(value, numchars) {
if (!value) {
return ''
}
try {
let mycar = value.substring(0, numchars)
if (value.length > numchars)
mycar += '...'
return mycar
} catch (e) {
return value
}
},
replaceStringAtEnd(inputString, searchString, replacement) {
// Create a regular expression that matches the searchString at the end of the inputString
const regex = new RegExp(searchString + '$');
@@ -4390,26 +4392,244 @@ module.exports = {
},
async getAnnuncioForTelegram(myrec, mydescr, userorig) {
addRowTelegram(icon, title, content, acapo, islink) {
let mystr = '';
let descrcontent = content;
if (islink) {
title = `<a href="${content}">${title}</a>`;
descrcontent = '';
}
mystr += `${icon} <strong>${title}</strong> ${icon}\n`;
if (descrcontent) {
mystr += `${descrcontent}\n`;
if (acapo) {
mystr += `\n`;
}
}
return mystr;
},
async getInCambioDiByRec(myrec) {
const contribtype = await Contribtype.findAllIdApp(idapp);
try {
let mystr = '';
for (const contribId of myrec.idContribType) {
const reccontr = contribtype.find((rec) => rec._id.toString() === contribId);
if (reccontr) {
if (mystr) {
mystr += ', ';
}
mystr += reccontr.label;
}
}
return mystr;
} catch (e) {
}
},
async getStatusSkillByRec(myrec, onlyifNoDiPersona) {
const statusskill = await StatusSkill.findAllIdApp(idapp);
try {
let mystr = '';
if (onlyifNoDiPersona) {
if ((myrec.idStatusSkill.length === 1) && (myrec.idStatusSkill[0] === shared_consts.STATUSSKILL_DI_PERSONA))
return ''
}
for (const status of myrec.idStatusSkill) {
const reccontr = statusskill.find((rec) => rec._id === status);
if (reccontr) {
if (mystr) {
mystr += ' e ';
}
mystr += reccontr.descr;
}
}
return mystr;
} catch (e) {
}
},
getIconByAdType(adType) {
if (adType === shared_consts.AdType.OFFRO)
return '🟢';
else if (adType === shared_consts.AdType.CERCO)
return '🔴';
return '';
},
async getCategoriaSkillByRec(myrec) {
const skillrec = await Skill.findAllIdApp(idapp);
try {
let mystr = '';
const rec = skillrec.find((rec) => rec._id === myrec.idSkill);
if (rec) {
mystr += rec.descr;
}
return mystr;
} catch (e) {
}
},
async getCategoriaGoodByRec(myrec) {
// const goodrec = await Good.findAllIdApp(idapp);
const secgoodrec = await SectorGood.findAllIdApp(idapp);
try {
let mystr = '';
const rec = secgoodrec.find((rec) => rec._id === myrec.idSectorGood);
// const rec = goodrec.find((rec) => rec._id === myrec.idSectorGood);
if (rec) {
mystr += rec.descr;
}
return mystr;
} catch (e) {
}
},
getComuniEProvinceByRec(myrec) {
try {
let mystr = '';
if (myrec.hasOwnProperty('mycities')) {
let ind = 0;
for (const city of myrec.mycities) {
if (ind > 0)
mystr += ', '
mystr += city.comune + ' (' + city.prov + ')';
ind++;
}
}
return mystr;
} catch (e) {
}
},
async getAnnuncioForTelegram(myrec, tablerec, mydescr, userorig, nuovo) {
try {
let dovestr = this.getDoveStrByEvent(myrec);
let descrestesa = await this.getDescrEstesaStrByEvent(myrec);
let contributo = myrec.contribstr;
let newdescr = '';
if (myrec.adType === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) {
newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
} else if (myrec.adType === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
} else if (myrec.adType === shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP) {
newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
let out = '';
let tiposcambio = ''
let iconascambio = '🟢';
let datastr = '';
let dovestr = '';
let organizedby = '';
let contributo = '';
if ((tablerec === shared_consts.TABLES_MYGOODS) || (tablerec === shared_consts.TABLES_MYSKILLS)) {
iconascambio = this.getIconByAdType(myrec.adType);
if (myrec.adType === shared_consts.AdType.OFFRO)
tiposcambio = 'Offro';
else if (myrec.adType === shared_consts.AdType.CERCO)
tiposcambio = 'Cerco';
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
tiposcambio = 'Offro ';
if (myrec.typeHosp === shared_consts.TYPEHOSP_OSPITALITA)
tiposcambio += 'Ospitalità';
else if (myrec.typeHosp === shared_consts.TYPEHOSP_SCAMBIOCASA)
tiposcambio += 'Scambio Casa';
} else if (tablerec === shared_consts.TABLES_MYBACHECAS) {
datastr = this.getstrDateTimeEvent(myrec);
organizedby = myrec.organisedBy;
contributo = myrec.contribstr;
}
let newdescrtelegram = i18n.__('NEW_ANNUNCIO_TELEGRAM', mydescr, dovestr, descrestesa, userorig);
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
if (nuovo) {
if (tablerec === shared_consts.TABLES_MYGOODS) {
newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
}
} else {
if (tablerec === shared_consts.TABLES_MYGOODS) {
newdescr = i18n.__('Good', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
newdescr = i18n.__('Service', userorig, mydescr);
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
newdescr = i18n.__('Hosp', userorig, mydescr);
}
}
let cat = '';
let status = '';
let online = false;
let solo_online = false;
if (tablerec === shared_consts.TABLES_MYGOODS) {
cat = await this.getCategoriaGoodByRec(myrec)
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
cat = await this.getCategoriaSkillByRec(myrec)
online = myrec.idStatusSkill.findIndex((id) => id === shared_consts.STATUSSKILL_ONLINE) >= 0
solo_online = online && myrec.idStatusSkill.length === 1
status = await this.getStatusSkillByRec(myrec, true);
if (status) {
status = ' ' + status;
}
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
cat = '';
}
// let out = i18n.__('NEW_ANNUNCIO_TELEGRAM', mydescr, dovestr, descrestesa, userorig);
return { newdescr, newdescrtelegram }
if (tiposcambio)
out += this.addRowTelegram(iconascambio, tiposcambio + status, '', false);
const url = this.getHostByIdApp(myrec.idapp) + shared_consts.getDirectoryByTable(tablerec, true) + myrec._id;
out += `<strong>${myrec.descr}</strong>\n\n`;
if (datastr)
out += this.addRowTelegram('🗓', 'Data Evento', datastr, true);
if (cat)
out += this.addRowTelegram('⭐️', 'Categoria', cat, true);
let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(myrec.note), 175, true, url);
if (descrcontent)
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true);
const localita = this.getComuniEProvinceByRec(myrec);
if (!solo_online)
out += this.addRowTelegram('🏠', 'Località', localita, true);
const incambiodi = await this.getInCambioDiByRec(myrec);
if (incambiodi)
out += this.addRowTelegram('⚖️', 'In cambio di', incambiodi, true);
if (contributo)
out += this.addRowTelegram('💰', 'Contributo', contributo, true);
let contatto = userorig;
try {
let username_telegram = myrec.profile.username_telegram;
if (username_telegram)
contatto = `@${username_telegram}`;
} catch (e) {
}
out += this.addRowTelegram('👤', 'Contatto', contatto, true);
out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true);
// out += i18n.__('ADDED_FROM', );
return { newdescr, newdescrtelegram: out }
} catch (e) {
console.error('Error', e);
}
@@ -4534,5 +4754,22 @@ module.exports = {
return inputString.replace(/[^\d.,]/g, '').replace(',', '.');
},
removeLastSpaceAndACapo(miastr) {
miastr = miastr.trimRight().replace(/[\n\r]+$/, '');
// Rimuove eventuali '<br>' in fondo alla stringa
// Rimuove eventuali '<div><br></div>' in fondo alla stringa
miastr = miastr.replace(/<\/div>$/, '');
miastr = miastr.replace(/<\/div>$/, '');
miastr = miastr.replace(/<br>$/, '');
miastr = miastr.replace(/<div><br><\/div>$/, '');
miastr = miastr.replace(/<br>$/, '');
miastr = miastr.trimRight().replace(/[\n\r]+$/, '');
miastr = miastr.replace(/<div><br><\/div>$/, '');
miastr = miastr.replace(/<div>$/, '');
miastr = miastr.replace(/<br>$/, '');
miastr = miastr.replace(/<br>$/, '');
return miastr;
}
};