mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
fix: missing doTopicAction, fix wrong api params
This commit is contained in:
@@ -4,10 +4,10 @@ const user = require('../user');
|
||||
const topics = require('../topics');
|
||||
const posts = require('../posts');
|
||||
const meta = require('../meta');
|
||||
const events = require('../events');
|
||||
const privileges = require('../privileges');
|
||||
|
||||
const apiHelpers = require('./helpers');
|
||||
const doTopicAction = apiHelpers.doTopicAction;
|
||||
|
||||
const socketHelpers = require('../socket.io/helpers');
|
||||
|
||||
const topicsAPI = module.exports;
|
||||
@@ -80,43 +80,43 @@ topicsAPI.reply = async function (caller, data) {
|
||||
|
||||
topicsAPI.delete = async function (caller, data) {
|
||||
await doTopicAction('delete', 'event:topic_deleted', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.restore = async function (caller, data) {
|
||||
await doTopicAction('restore', 'event:topic_restored', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.purge = async function (caller, data) {
|
||||
await doTopicAction('purge', 'event:topic_purged', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.pin = async function (caller, data) {
|
||||
await doTopicAction('pin', 'event:topic_pinned', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.unpin = async function (caller, data) {
|
||||
await doTopicAction('unpin', 'event:topic_unpinned', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.lock = async function (caller, data) {
|
||||
await doTopicAction('lock', 'event:topic_locked', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.unlock = async function (caller, data) {
|
||||
await doTopicAction('unlock', 'event:topic_unlocked', caller, {
|
||||
tids: [data.tid],
|
||||
tids: data.tids,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -131,42 +131,3 @@ topicsAPI.ignore = async function (caller, data) {
|
||||
topicsAPI.unfollow = async function (caller, data) {
|
||||
await topics.unfollow(data.tid, caller.uid);
|
||||
};
|
||||
|
||||
async function doTopicAction(action, event, caller, { tids }) {
|
||||
if (!Array.isArray(tids)) {
|
||||
throw new Error('[[error:invalid-tid]]');
|
||||
}
|
||||
|
||||
const exists = (await Promise.all(tids.map(async tid => await topics.exists(tid)))).every(Boolean);
|
||||
if (!exists) {
|
||||
throw new Error('[[error:no-topic]]');
|
||||
}
|
||||
|
||||
if (typeof topics.tools[action] !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
const uids = await user.getUidsFromSet('users:online', 0, -1);
|
||||
|
||||
await Promise.all(tids.map(async function (tid) {
|
||||
const title = await topics.getTopicField(tid, 'title');
|
||||
const data = await topics.tools[action](tid, caller.uid);
|
||||
const notifyUids = await privileges.categories.filterUids('topics:read', data.cid, uids);
|
||||
socketHelpers.emitToUids(event, data, notifyUids);
|
||||
await logTopicAction(action, caller, tid, title);
|
||||
}));
|
||||
}
|
||||
|
||||
async function logTopicAction(action, req, tid, title) {
|
||||
var actionsToLog = ['delete', 'restore', 'purge'];
|
||||
if (!actionsToLog.includes(action)) {
|
||||
return;
|
||||
}
|
||||
await events.log({
|
||||
type: 'topic-' + action,
|
||||
uid: req.uid,
|
||||
ip: req.ip,
|
||||
tid: tid,
|
||||
title: String(title),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user