Skip to content

Node.js based forum software built for the modern web

fix: update Topics.post and Topics.reply so that plugins can modify uid (or redirect a reply to a different topic)

Julian Lam7777812e62ec
diff --git a/src/topics/create.js b/src/topics/create.js
index 666d203648..92a9229ed7 100644
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@ -76,7 +76,7 @@ module.exports = function (Topics) {
};
Topics.post = async function (data) {
- const { uid } = data;
+ let { uid } = data;
data.title = String(data.title).trim();
data.tags = data.tags || [];
if (data.content) {
@@ -105,8 +105,9 @@ module.exports = function (Topics) {
if (!data.fromQueue) {
await user.isReadyToPost(data.uid, data.cid);
}
- const filteredData = await plugins.hooks.fire('filter:topic.post', data);
- data = filteredData;
+
+ data = await plugins.hooks.fire('filter:topic.post', data);
+ ({ uid } = data); // uid was explicitly destructured at top, so update if changed
const tid = await Topics.create(data);
let postData = data;
@@ -152,6 +153,7 @@ module.exports = function (Topics) {
};
Topics.reply = async function (data) {
+ data = await plugins.hooks.fire('filter:topic.reply', data);
const { tid } = data;
const { uid } = data;
@@ -165,7 +167,6 @@ module.exports = function (Topics) {
if (!data.fromQueue) {
await user.isReadyToPost(uid, data.cid);
}
- await plugins.hooks.fire('filter:topic.reply', data);
if (data.content) {
data.content = utils.rtrim(data.content);
}