feat: translate bodyShort

turns [[notifications:upvoted_your_post_in, test1, Vote *for* NodeBB :ballot_box_with_ballot:]]   into <strong>test1</strong> has upvoted your post in <strong>Vote *for* NodeBB :ballot_box_with_ballot:</strong>. so emoji plugin can parse emojis and they don't get escaped by translator client side
isekai-main
Barış Soner Uşaklı 2 years ago
parent cdeaef6b7c
commit ed15cbb06a

@ -9,6 +9,8 @@ const meta = require('../meta');
const notifications = require('../notifications'); const notifications = require('../notifications');
const privileges = require('../privileges'); const privileges = require('../privileges');
const plugins = require('../plugins'); const plugins = require('../plugins');
const translator = require('../translator');
const user = require('./index');
const utils = require('../utils'); const utils = require('../utils');
const UserNotifications = module.exports; const UserNotifications = module.exports;
@ -99,9 +101,10 @@ UserNotifications.getNotifications = async function (nids, uid) {
return []; return [];
} }
const [notifObjs, hasRead] = await Promise.all([ const [notifObjs, hasRead, userSettings] = await Promise.all([
notifications.getMultiple(nids), notifications.getMultiple(nids),
db.isSortedSetMembers(`uid:${uid}:notifications:read`, nids), db.isSortedSetMembers(`uid:${uid}:notifications:read`, nids),
user.getSettings(uid),
]); ]);
const deletedNids = []; const deletedNids = [];
@ -119,6 +122,12 @@ UserNotifications.getNotifications = async function (nids, uid) {
await deleteUserNids(deletedNids, uid); await deleteUserNids(deletedNids, uid);
notificationData = await notifications.merge(notificationData); notificationData = await notifications.merge(notificationData);
await Promise.all(notificationData.map(async (n) => {
if (n && n.bodyShort) {
n.bodyShort = await translator.translate(n.bodyShort, userSettings.userLang);
}
}));
const result = await plugins.hooks.fire('filter:user.notifications.getNotifications', { const result = await plugins.hooks.fire('filter:user.notifications.getNotifications', {
uid: uid, uid: uid,
notifications: notificationData, notifications: notificationData,

Loading…
Cancel
Save