Node.js based forum software built for the modern web
feat: parse moderation notes as markdown
Barış Soner Uşaklı7d24b04b3b72
diff --git a/public/src/client/account/info.js b/public/src/client/account/info.jsindex 71adca7b11..f99bd7c36d 100644--- a/public/src/client/account/info.js+++ b/public/src/client/account/info.js@@ -13,20 +13,13 @@ define('forum/account/info', ['forum/account/header', 'alerts', 'forum/account/sfunction handleModerationNote() {$('[component="account/save-moderation-note"]').on('click', function () {const note = $('[component="account/moderation-note"]').val();- socket.emit('user.setModerationNote', { uid: ajaxify.data.uid, note: note }, function (err) {+ socket.emit('user.setModerationNote', { uid: ajaxify.data.uid, note: note }, function (err, notes) {if (err) {return alerts.error(err);}$('[component="account/moderation-note"]').val('');- alerts.success('[[user:info.moderation-note.success]]');- const timestamp = Date.now();- const data = [{- note: utils.escapeHTML(note),- user: app.user,- timestamp: timestamp,- timestampISO: utils.toISOString(timestamp),- }];- app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: data }, function (html) {++ app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: notes }, function (html) {$('[component="account/moderation-note/list"]').prepend(html);html.find('.timeago').timeago();});diff --git a/src/socket.io/user.js b/src/socket.io/user.jsindex 443e73678f..63620247f9 100644--- a/src/socket.io/user.js+++ b/src/socket.io/user.js@@ -152,6 +152,7 @@ SocketUser.setModerationNote = async function (socket, data) {}await user.appendModerationNote({ uid: data.uid, noteData });+ return await user.getModerationNotes(data.uid, 0, 0);};SocketUser.deleteUpload = async function (socket, data) {diff --git a/src/user/info.js b/src/user/info.jsindex ff67dbd3cb..a013f746ff 100644--- a/src/user/info.js+++ b/src/user/info.js@@ -7,6 +7,7 @@ const db = require('../database');const posts = require('../posts');const topics = require('../topics');const utils = require('../utils');+const plugins = require('../plugins');const Flags = require('../flags');module.exports = function (User) {@@ -114,22 +115,20 @@ module.exports = function (User) {const notes = await db.getObjects(keys);const uids = [];- const noteData = notes.map((note) => {+ notes.forEach((note) => {if (note) {uids.push(note.uid);note.timestampISO = utils.toISOString(note.timestamp);- note.note = validator.escape(String(note.note));}- return note;});-const userData = await User.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture']);- noteData.forEach((note, index) => {+ await Promise.all(notes.map(async (note, index) => {if (note) {+ note.note = await plugins.hooks.fire('filter:parse.raw', String(note.note));note.user = userData[index];}- });- return noteData;+ }));+ return notes;};User.appendModerationNote = async ({ uid, noteData }) => {