mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: update Topics.post and Topics.reply so that plugins can modify uid (or redirect a reply to a different topic)
/cc @antosik
This commit is contained in:
@@ -76,7 +76,7 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.post = async function (data) {
|
Topics.post = async function (data) {
|
||||||
const { uid } = data;
|
let { uid } = data;
|
||||||
data.title = String(data.title).trim();
|
data.title = String(data.title).trim();
|
||||||
data.tags = data.tags || [];
|
data.tags = data.tags || [];
|
||||||
if (data.content) {
|
if (data.content) {
|
||||||
@@ -105,8 +105,9 @@ module.exports = function (Topics) {
|
|||||||
if (!data.fromQueue) {
|
if (!data.fromQueue) {
|
||||||
await user.isReadyToPost(data.uid, data.cid);
|
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);
|
const tid = await Topics.create(data);
|
||||||
|
|
||||||
let postData = data;
|
let postData = data;
|
||||||
@@ -152,6 +153,7 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.reply = async function (data) {
|
Topics.reply = async function (data) {
|
||||||
|
data = await plugins.hooks.fire('filter:topic.reply', data);
|
||||||
const { tid } = data;
|
const { tid } = data;
|
||||||
const { uid } = data;
|
const { uid } = data;
|
||||||
|
|
||||||
@@ -165,7 +167,6 @@ module.exports = function (Topics) {
|
|||||||
if (!data.fromQueue) {
|
if (!data.fromQueue) {
|
||||||
await user.isReadyToPost(uid, data.cid);
|
await user.isReadyToPost(uid, data.cid);
|
||||||
}
|
}
|
||||||
await plugins.hooks.fire('filter:topic.reply', data);
|
|
||||||
if (data.content) {
|
if (data.content) {
|
||||||
data.content = utils.rtrim(data.content);
|
data.content = utils.rtrim(data.content);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user