Skip to content

Node.js based forum software built for the modern web

refactor(topic-events): fire topic event logging in topics/tools instead, pass uid into payload

Julian Lam425eca145ba2
diff --git a/src/api/helpers.js b/src/api/helpers.js
index c5e7c1d727..23909e655d 100644
--- a/src/api/helpers.js
+++ b/src/api/helpers.js
@@ -63,11 +63,6 @@ exports.doTopicAction = async function (action, event, caller, { tids }) {
};
async function logTopicAction(action, req, tid, title) {
- // No 'purge' topic event (since topic is now gone)
- if (action !== 'purge') {
- await topics.events.log(tid, { type: action });
- }
-
// Only log certain actions to system event log
var actionsToLog = ['delete', 'restore', 'purge'];
if (!actionsToLog.includes(action)) {
diff --git a/src/topics/tools.js b/src/topics/tools.js
index 8d04f4603e..7232dc83e2 100644
--- a/src/topics/tools.js
+++ b/src/topics/tools.js
@@ -44,6 +44,7 @@ module.exports = function (Topics) {
} else {
await Topics.restore(data.topicData.tid);
}
+ await Topics.events.log(tid, { type: isDelete ? 'delete' : 'restore', uid });
data.topicData.deleted = data.isDelete ? 1 : 0;
@@ -94,6 +95,7 @@ module.exports = function (Topics) {
throw new Error('[[error:no-privileges]]');
}
await Topics.setTopicField(tid, 'locked', lock ? 1 : 0);
+ await Topics.events.log(tid, { type: lock ? 'lock' : 'unlock', uid });
topicData.isLocked = lock; // deprecate in v2.0
topicData.locked = lock;
@@ -152,6 +154,7 @@ module.exports = function (Topics) {
const promises = [
Topics.setTopicField(tid, 'pinned', pin ? 1 : 0),
+ Topics.events.log(tid, { type: pin ? 'pin' : 'unpin', uid }),
];
if (pin) {
promises.push(db.sortedSetAdd('cid:' + topicData.cid + ':tids:pinned', Date.now(), tid));