mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
refactor: topic follow/ignore to use api lib
This commit is contained in:
@@ -120,6 +120,18 @@ topicsAPI.unlock = async function (caller, data) {
|
||||
});
|
||||
};
|
||||
|
||||
topicsAPI.follow = async function (caller, data) {
|
||||
await topics.follow(data.tid, caller.uid);
|
||||
};
|
||||
|
||||
topicsAPI.ignore = async function (caller, data) {
|
||||
await topics.ignore(data.tid, caller.uid);
|
||||
};
|
||||
|
||||
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]]');
|
||||
|
||||
@@ -57,17 +57,17 @@ Topics.unlock = async (req, res) => {
|
||||
};
|
||||
|
||||
Topics.follow = async (req, res) => {
|
||||
await topics.follow(req.params.tid, req.user.uid);
|
||||
await api.topics.follow(req, req.params);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Topics.ignore = async (req, res) => {
|
||||
await topics.ignore(req.params.tid, req.user.uid);
|
||||
await api.topics.ignore(req, req.params);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Topics.unfollow = async (req, res) => {
|
||||
await topics.unfollow(req.params.tid, req.user.uid);
|
||||
await api.topics.unfollow(req, req.params);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ SocketTopics.changeWatching = async function (socket, data) {
|
||||
}
|
||||
|
||||
sockets.warnDeprecated(socket, 'PUT/DELETE /api/v3/topics/:tid/(follow|ignore)');
|
||||
await followCommand(topics[data.type], socket, data.tid);
|
||||
await followCommand(data.type, socket, data.tid);
|
||||
};
|
||||
|
||||
SocketTopics.follow = async function (socket, tid) {
|
||||
sockets.warnDeprecated(socket, 'PUT /api/v3/topics/:tid/follow');
|
||||
await followCommand(topics.follow, socket, tid);
|
||||
await followCommand('follow', socket, tid);
|
||||
};
|
||||
|
||||
async function followCommand(method, socket, tid) {
|
||||
@@ -75,7 +75,7 @@ async function followCommand(method, socket, tid) {
|
||||
throw new Error('[[error:not-logged-in]]');
|
||||
}
|
||||
|
||||
await method(tid, socket.uid);
|
||||
await api.topics[method](socket, { tid });
|
||||
}
|
||||
|
||||
SocketTopics.isFollowed = async function (socket, tid) {
|
||||
|
||||
Reference in New Issue
Block a user