- Migliorata la Notifica degli Eventi su Telegram

- Gli annunci (beni/servizi/ospitalità) ora possono essere visti anche tramite un link, anche per chi non è dentro alla App.
- Aggiunto bottone "Aggiorna" per aggiornare il Saldo attuale.
- I "Conti Collettivi" ora vengono chiamati Gruppi (o Conto di Gruppo).
This commit is contained in:
Surya Paolo
2023-10-01 01:24:47 +02:00
parent 142dcadca9
commit 04c8e929ee
19 changed files with 348 additions and 112 deletions

View File

@@ -1520,6 +1520,40 @@ module.exports = {
return msg;
},
htmlToTelegramText(html) {
try {
const withMarkdown = html
.replace(/<strong>(.*?)<\/strong>/g, '*$1*')
.replace(/<b>(.*?)<\/b>/g, '*$1*')
.replace(/<em>(.*?)<\/em>/g, '_$1_')
.replace(/<u>(.*?)<\/u>/g, '__$1__');
// Remove other HTML tags
const plainText = withMarkdown.replace(/<[^>]*>/g, '');
// Replace HTML entities with their equivalent Markdown or plain text representations
const replacements = [
{ pattern: /&amp;/g, replacement: '&' },
{ pattern: /&lt;/g, replacement: '<' },
{ pattern: /&gt;/g, replacement: '>' },
{ pattern: /&quot;/g, replacement: '"' },
{ pattern: /&#39;/g, replacement: "'" },
];
let telegramText = plainText;
replacements.forEach((replacement) => {
telegramText = telegramText.replace(replacement.pattern, replacement.replacement);
});
return telegramText;
} catch (e) {
console.error(e);
};
},
convertTexttoHtml(myhtml) {
// let msg = myhtml;
// msg = msg.replace('\n', '<br>');
@@ -2067,9 +2101,11 @@ module.exports = {
},
{
$unwind: '$myreact',
$unwind: {
path: "$myreact",
preserveNullAndEmptyArrays: true,
},
},
/*{
$lookup: {
from: "reactions",
@@ -2170,6 +2206,11 @@ module.exports = {
];
if (true) {
// RIMUOVI
// query = {};
}
if (Object.keys(query).length > 0) {
const numtabbacheca = this.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
if (numtab === numtabbacheca) {
@@ -2939,7 +2980,7 @@ module.exports = {
);
if (this.testing()) {
console.log('query', query);
// console.log('query', query);
}
return query;
@@ -3300,6 +3341,19 @@ module.exports = {
}
},
getstrTime(mytimestamp) {
// Create a Date object with your desired date
const date = new Date(mytimestamp); // You can replace this with your specific date
// Get the hour and minute components from the date
const hours = date.getHours();
const minutes = date.getMinutes();
// Format the hour and minute components as HH:MM
const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
return formattedTime
},
getstrDateShort(mydate, lang) {
if (mydate) {
// console.log('getstrDate', mytimestamp)
@@ -4204,6 +4258,88 @@ module.exports = {
getAhref(username, link) {
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 + '$');
// Use the replace method with the regular expression to replace the string
const result = inputString.replace(regex, replacement);
return result;
},
getstrDateTimeEvent(myevent) {
let mystr = '';
// is same day?
if (this.getstrDateShort(myevent.dateTimeStart) === this.getstrDateShort(myevent.dateTimeEnd)) {
mystr = i18n.__('DATEDAYONLY', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
this.getstrTime(myevent.dateTimeEnd))
} else {
mystr = i18n.__('DATE_2DAYS', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
this.getstrDateLong(myevent.dateTimeEnd), this.getstrTime(myevent.dateTimeEnd))
}
return '🗓 ' + mystr;
},
getDoveStrByEvent(myrec) {
let dove = '🏠 ';
if (myrec.mycities && myrec.mycities.length > 0) {
dove += myrec.mycities[0].comune + ' (' + myrec.mycities[0].prov + ')'
}
return dove;
},
async getDescrEstesaStrByEvent(myrec) {
let mystr = '';
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '</div>', ''), 400);
if (mystr)
mystr = ' ' + mystr
return mystr;
},
async getEventForTelegram(myrec, mydescr, userorig) {
try {
let datastr = this.getstrDateTimeEvent(myrec);
let dovestr = this.getDoveStrByEvent(myrec);
let descrestesa = await this.getDescrEstesaStrByEvent(myrec);
let organizedby = myrec.organisedBy;
let contributo = myrec.contribstr;
let newdescr = i18n.__('NEW_EVENT', userorig, datastr, mydescr, dovestr);
let newdescrtelegram = i18n.__('NEW_EVENT_TELEGRAM', datastr, mydescr, dovestr, descrestesa, userorig);
if (organizedby) {
newdescrtelegram += i18n.__('ORGANIZED_BY', organizedby);
}
if (contributo) {
newdescrtelegram += i18n.__('CONTRIB', contributo);
}
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
return { newdescr, newdescrtelegram }
} catch (e) {
console.error('Error', e);
}
},
};

View File

@@ -259,9 +259,10 @@ module.exports = {
actions: recnotif.actions ? recnotif.actions : [],
id: recnotif._id,
textaddTelegram: recnotif.textaddTelegram ? recnotif.textaddTelegram : '',
textcontent_Telegram: recnotif.textcontent_Telegram ? recnotif.textcontent_Telegram : '',
linkaddTelegram: recnotif.linkaddTelegram ? recnotif.linkaddTelegram : '',
};
if (tools.isBitActive(recnotif.typesend, shared_consts.MessageOptions.Notify_ByPushNotification) && this.checkifSendPushNotification) {
params.typesend = params.typesend + shared_consts.TypeSend.PUSH_NOTIFICATION;
invia = true;
@@ -386,7 +387,7 @@ module.exports = {
for (const user of arrusers) {
const mytitle = await tools.convertSpecialTags(user, params.title);
const mycontent = await tools.convertSpecialTags(user, params.content);
const mycontent = await tools.convertSpecialTags(user, params.textcontent_Telegram ? params.textcontent_Telegram : params.content);
let usernotifprofile = null;
if (user.profile.notifs)

View File

@@ -3,6 +3,7 @@ module.exports = {
CHECK_READ_GUIDELINES: 1,
CHECK_SEE_VIDEO_PRINCIPI: 2,
},
LIMIT_NOTIF_FOR_USER: 200,
QUERYTYPE_MYGROUP: 1,
QUERYTYPE_REFUSED_USER_GRP: 2,
@@ -732,7 +733,9 @@ module.exports = {
groupname: 1,
lasttimeonline: 1,
comune: 1,
myreact: 1,
mycities: 1,
lang: 1,
'profile.img': 1,
'profile.mygroups': 1,
'profile.mycircuits': 1,