Node.js based forum software built for the modern web
refactor: topic follow/ignore to use api lib
Julian Lam9ee3cb9b620d
diff --git a/src/api/topics.js b/src/api/topics.jsindex bda48d59da..b3115f3a40 100644--- a/src/api/topics.js+++ b/src/api/topics.js@@ -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]]');diff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.jsindex ff35ca62c2..9e56bd74df 100644--- a/src/controllers/write/topics.js+++ b/src/controllers/write/topics.js@@ -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);};diff --git a/src/socket.io/topics.js b/src/socket.io/topics.jsindex ffbab91254..ecdc0e12cd 100644--- a/src/socket.io/topics.js+++ b/src/socket.io/topics.js@@ -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) {