feat: replace relative urls to absolute before sending email notifs

https://github.com/NodeBB/NodeBB/pull/8366/files
v1.18.x
Barış Soner Uşaklı 5 years ago
parent c495aacc3e
commit 1e5981c0d6

@ -8,6 +8,7 @@ const _ = require('lodash');
const db = require('./database'); const db = require('./database');
const User = require('./user'); const User = require('./user');
const posts = require('./posts');
const groups = require('./groups'); const groups = require('./groups');
const meta = require('./meta'); const meta = require('./meta');
const batch = require('./batch'); const batch = require('./batch');
@ -172,14 +173,16 @@ async function pushToUids(uids, notification) {
if (['new-reply', 'new-chat'].includes(notification.type)) { if (['new-reply', 'new-chat'].includes(notification.type)) {
notification['cta-type'] = notification.type; notification['cta-type'] = notification.type;
} }
let body = notification.bodyLong || '';
body = posts.relativeToAbsolute(body, posts.urlRegex);
body = posts.relativeToAbsolute(body, posts.imgRegex);
await async.eachLimit(uids, 3, function (uid, next) { await async.eachLimit(uids, 3, function (uid, next) {
emailer.send('notification', uid, { emailer.send('notification', uid, {
path: notification.path, path: notification.path,
notification_url: notification.path.startsWith('http') ? notification.path : nconf.get('url') + notification.path, notification_url: notification.path.startsWith('http') ? notification.path : nconf.get('url') + notification.path,
subject: utils.stripHTMLTags(notification.subject || '[[notifications:new_notification]]'), subject: utils.stripHTMLTags(notification.subject || '[[notifications:new_notification]]'),
intro: utils.stripHTMLTags(notification.bodyShort), intro: utils.stripHTMLTags(notification.bodyShort),
body: notification.bodyLong || '', body: body,
notification: notification, notification: notification,
showUnsubscribe: true, showUnsubscribe: true,
}, next); }, next);

@ -77,7 +77,10 @@ module.exports = function (Posts) {
}; };
Posts.relativeToAbsolute = function (content, regex) { Posts.relativeToAbsolute = function (content, regex) {
// Turns relative links in post body to absolute urls // Turns relative links in content to absolute urls
if (!content) {
return content;
}
var parsed; var parsed;
var current = regex.regex.exec(content); var current = regex.regex.exec(content);
var absolute; var absolute;

@ -2,7 +2,6 @@
'use strict'; 'use strict';
const db = require('../database'); const db = require('../database');
const posts = require('../posts');
const notifications = require('../notifications'); const notifications = require('../notifications');
const privileges = require('../privileges'); const privileges = require('../privileges');
const plugins = require('../plugins'); const plugins = require('../plugins');
@ -163,9 +162,6 @@ module.exports = function (Topics) {
title = utils.decodeHTMLEntities(title); title = utils.decodeHTMLEntities(title);
} }
postData.content = posts.relativeToAbsolute(postData.content, posts.urlRegex);
postData.content = posts.relativeToAbsolute(postData.content, posts.imgRegex);
const notification = await notifications.create({ const notification = await notifications.create({
subject: title, subject: title,
bodyLong: postData.content, bodyLong: postData.content,

Loading…
Cancel
Save