mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
feat: parse moderation notes as markdown
https://github.com/NodeBB/NodeBB/issues/12477
This commit is contained in:
@@ -13,20 +13,13 @@ define('forum/account/info', ['forum/account/header', 'alerts', 'forum/account/s
|
|||||||
function handleModerationNote() {
|
function handleModerationNote() {
|
||||||
$('[component="account/save-moderation-note"]').on('click', function () {
|
$('[component="account/save-moderation-note"]').on('click', function () {
|
||||||
const note = $('[component="account/moderation-note"]').val();
|
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) {
|
if (err) {
|
||||||
return alerts.error(err);
|
return alerts.error(err);
|
||||||
}
|
}
|
||||||
$('[component="account/moderation-note"]').val('');
|
$('[component="account/moderation-note"]').val('');
|
||||||
alerts.success('[[user:info.moderation-note.success]]');
|
|
||||||
const timestamp = Date.now();
|
app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: notes }, function (html) {
|
||||||
const data = [{
|
|
||||||
note: utils.escapeHTML(note),
|
|
||||||
user: app.user,
|
|
||||||
timestamp: timestamp,
|
|
||||||
timestampISO: utils.toISOString(timestamp),
|
|
||||||
}];
|
|
||||||
app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: data }, function (html) {
|
|
||||||
$('[component="account/moderation-note/list"]').prepend(html);
|
$('[component="account/moderation-note/list"]').prepend(html);
|
||||||
html.find('.timeago').timeago();
|
html.find('.timeago').timeago();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ SocketUser.setModerationNote = async function (socket, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await user.appendModerationNote({ uid: data.uid, noteData });
|
await user.appendModerationNote({ uid: data.uid, noteData });
|
||||||
|
return await user.getModerationNotes(data.uid, 0, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.deleteUpload = async function (socket, data) {
|
SocketUser.deleteUpload = async function (socket, data) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const db = require('../database');
|
|||||||
const posts = require('../posts');
|
const posts = require('../posts');
|
||||||
const topics = require('../topics');
|
const topics = require('../topics');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
const plugins = require('../plugins');
|
||||||
const Flags = require('../flags');
|
const Flags = require('../flags');
|
||||||
|
|
||||||
module.exports = function (User) {
|
module.exports = function (User) {
|
||||||
@@ -114,22 +115,20 @@ module.exports = function (User) {
|
|||||||
const notes = await db.getObjects(keys);
|
const notes = await db.getObjects(keys);
|
||||||
const uids = [];
|
const uids = [];
|
||||||
|
|
||||||
const noteData = notes.map((note) => {
|
notes.forEach((note) => {
|
||||||
if (note) {
|
if (note) {
|
||||||
uids.push(note.uid);
|
uids.push(note.uid);
|
||||||
note.timestampISO = utils.toISOString(note.timestamp);
|
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']);
|
const userData = await User.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture']);
|
||||||
noteData.forEach((note, index) => {
|
await Promise.all(notes.map(async (note, index) => {
|
||||||
if (note) {
|
if (note) {
|
||||||
|
note.note = await plugins.hooks.fire('filter:parse.raw', String(note.note));
|
||||||
note.user = userData[index];
|
note.user = userData[index];
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
return noteData;
|
return notes;
|
||||||
};
|
};
|
||||||
|
|
||||||
User.appendModerationNote = async ({ uid, noteData }) => {
|
User.appendModerationNote = async ({ uid, noteData }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user