correzione numseen, numfav, ...: ora li ho aggiunti alle tabelle...
This commit is contained in:
@@ -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: /&/g, replacement: '&' },
|
||||
{ pattern: /</g, replacement: '<' },
|
||||
{ pattern: />/g, replacement: '>' },
|
||||
{ pattern: /"/g, replacement: '"' },
|
||||
{ pattern: /'/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>');
|
||||
@@ -2005,9 +2039,10 @@ module.exports = {
|
||||
|
||||
addNumFavoriteAndBookmarkToQuery(idapp, numtab) {
|
||||
|
||||
let query = {};
|
||||
let query = [];
|
||||
|
||||
try {
|
||||
/*
|
||||
query =
|
||||
[
|
||||
{
|
||||
@@ -2067,109 +2102,19 @@ module.exports = {
|
||||
},
|
||||
|
||||
{
|
||||
$unwind: '$myreact',
|
||||
},
|
||||
|
||||
/*{
|
||||
$lookup: {
|
||||
from: "reactions",
|
||||
let: {
|
||||
tab: 2,
|
||||
id: '$_id',
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$idrec', '$$id'] },
|
||||
{ $eq: ['$tab', 2] },
|
||||
{ $eq: ['$idapp', '13'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
myid: '$_id',
|
||||
_id: 0,
|
||||
idapp: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
fav: 1,
|
||||
seen: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'items',
|
||||
$unwind: {
|
||||
path: "$myreact",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$items"
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
let: {
|
||||
itemId: { $toObjectId: "$items.userId" },
|
||||
items: "$items"
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: [
|
||||
"$_id",
|
||||
"$$itemId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
"$$items",
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
as: "myreact"
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$_id",
|
||||
userId: {
|
||||
$first: "$userId"
|
||||
},
|
||||
descr: {
|
||||
$first: "$descr"
|
||||
},
|
||||
myreact: {
|
||||
$push: {
|
||||
$first: "$myreact"
|
||||
},
|
||||
|
||||
},
|
||||
firstDoc: {
|
||||
$first: "$$ROOT"
|
||||
},
|
||||
}
|
||||
} */
|
||||
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
if (true) {
|
||||
// RIMUOVI
|
||||
// query = {};
|
||||
}
|
||||
|
||||
if (Object.keys(query).length > 0) {
|
||||
const numtabbacheca = this.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
|
||||
if (numtab === numtabbacheca) {
|
||||
@@ -2177,8 +2122,13 @@ module.exports = {
|
||||
query = [...query, ...queryadd];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
proj = {
|
||||
numseen: 1,
|
||||
numfav: 1,
|
||||
numbook: 1,
|
||||
numattend: 1,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -2900,9 +2850,9 @@ module.exports = {
|
||||
|
||||
if (params.options && this.isBitActive(params.options,
|
||||
shared_consts.OPTIONS_ADD_COUNT_FAVORITE)) {
|
||||
objadd = this.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
if (Object.keys(objadd.query).length > 0)
|
||||
query = [...query, ...objadd.query];
|
||||
// objadd = this.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
// if (Object.keys(objadd.query).length > 0)
|
||||
// query = [...query, ...objadd.query];
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -2939,7 +2889,7 @@ module.exports = {
|
||||
);
|
||||
|
||||
if (this.testing()) {
|
||||
console.log('query', query);
|
||||
// console.log('query', query);
|
||||
}
|
||||
|
||||
return query;
|
||||
@@ -3300,6 +3250,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 +4167,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);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
@@ -156,6 +157,14 @@ module.exports = {
|
||||
SET_ATTEND: 4,
|
||||
},
|
||||
|
||||
REACTIONS_FIELD:
|
||||
{
|
||||
numseen: 1,
|
||||
numbook: 1,
|
||||
numfav: 1,
|
||||
numattend: 1,
|
||||
},
|
||||
|
||||
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
|
||||
@@ -732,7 +741,9 @@ module.exports = {
|
||||
groupname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
myreact: 1,
|
||||
mycities: 1,
|
||||
lang: 1,
|
||||
'profile.img': 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.mycircuits': 1,
|
||||
@@ -753,6 +764,8 @@ module.exports = {
|
||||
if (proj_add)
|
||||
proj = Object.assign({}, proj, proj_add);
|
||||
|
||||
proj = {...proj, ...this.REACTIONS_FIELD};
|
||||
|
||||
if (table) {
|
||||
let proj_add3 = this.getProjectByTable(table);
|
||||
proj = Object.assign({}, proj, proj_add3);
|
||||
|
||||
Reference in New Issue
Block a user