mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
feat(writeapi): topic follow/ignore
This commit is contained in:
@@ -107,31 +107,27 @@ define('forum/topic/threadTools', [
|
||||
changeWatching('follow');
|
||||
});
|
||||
topicContainer.on('click', '[component="topic/not-following"]', function () {
|
||||
changeWatching('unfollow');
|
||||
changeWatching('follow', 0);
|
||||
});
|
||||
topicContainer.on('click', '[component="topic/ignoring"]', function () {
|
||||
changeWatching('ignore');
|
||||
});
|
||||
|
||||
function changeWatching(type) {
|
||||
socket.emit('topics.changeWatching', { tid: tid, type: type }, function (err) {
|
||||
if (err) {
|
||||
return app.alert({
|
||||
type: 'danger',
|
||||
alert_id: 'topic_follow',
|
||||
title: '[[global:please_log_in]]',
|
||||
message: '[[topic:login_to_subscribe]]',
|
||||
timeout: 5000,
|
||||
});
|
||||
}
|
||||
function changeWatching(type, state = 1) {
|
||||
const method = state ? 'put' : 'del';
|
||||
api[method](`/topics/${tid}/${type}`, {}, () => {
|
||||
var message = '';
|
||||
if (type === 'follow') {
|
||||
message = '[[topic:following_topic.message]]';
|
||||
} else if (type === 'unfollow') {
|
||||
message = '[[topic:not_following_topic.message]]';
|
||||
message = state ? '[[topic:following_topic.message]]' : '[[topic:not_following_topic.message]]';
|
||||
} else if (type === 'ignore') {
|
||||
message = '[[topic:ignoring_topic.message]]';
|
||||
message = state ? '[[topic:ignoring_topic.message]]' : '[[topic:not_following_topic.message]]';
|
||||
}
|
||||
|
||||
// From here on out, type changes to 'unfollow' if state is falsy
|
||||
if (!state) {
|
||||
type = 'unfollow';
|
||||
}
|
||||
|
||||
setFollowState(type);
|
||||
|
||||
app.alert({
|
||||
@@ -142,6 +138,14 @@ define('forum/topic/threadTools', [
|
||||
});
|
||||
|
||||
$(window).trigger('action:topics.changeWatching', { tid: tid, type: type });
|
||||
}, () => {
|
||||
app.alert({
|
||||
type: 'danger',
|
||||
alert_id: 'topic_follow',
|
||||
title: '[[global:please_log_in]]',
|
||||
message: '[[topic:login_to_subscribe]]',
|
||||
timeout: 5000,
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
|
@@ -123,6 +123,21 @@ Topics.unlock = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Topics.follow = async (req, res) => {
|
||||
await topics.follow(req.params.tid, req.user.uid);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Topics.ignore = async (req, res) => {
|
||||
await topics.ignore(req.params.tid, req.user.uid);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Topics.unfollow = async (req, res) => {
|
||||
await topics.unfollow(req.params.tid, req.user.uid);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
async function doTopicAction(action, event, socket, { tids }) {
|
||||
if (!Array.isArray(tids)) {
|
||||
throw new Error('[[error:invalid-tid]]');
|
||||
|
@@ -23,6 +23,10 @@ module.exports = function () {
|
||||
setupApiRoute(router, '/:tid/lock', middleware, [...middlewares, middleware.assertTopic], 'put', controllers.write.topics.lock);
|
||||
setupApiRoute(router, '/:tid/lock', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.unlock);
|
||||
|
||||
setupApiRoute(router, '/:tid/follow', middleware, [...middlewares, middleware.assertTopic], 'put', controllers.write.topics.follow);
|
||||
setupApiRoute(router, '/:tid/follow', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.unfollow);
|
||||
setupApiRoute(router, '/:tid/ignore', middleware, [...middlewares, middleware.assertTopic], 'put', controllers.write.topics.ignore);
|
||||
setupApiRoute(router, '/:tid/ignore', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.unfollow); // intentional, unignore == unfollow
|
||||
|
||||
// app.route('/:tid/follow')
|
||||
// .put(apiMiddleware.requireUser, apiMiddleware.validateTid, function(req, res) {
|
||||
|
@@ -82,10 +82,13 @@ SocketTopics.changeWatching = async function (socket, data) {
|
||||
if (!commands.includes(data.type)) {
|
||||
throw new Error('[[error:invalid-command]]');
|
||||
}
|
||||
|
||||
sockets.warnDeprecated(socket, 'PUT/DELETE /api/v1/topics/:tid/(follow|ignore)');
|
||||
await followCommand(topics[data.type], socket, data.tid);
|
||||
};
|
||||
|
||||
SocketTopics.follow = async function (socket, tid) {
|
||||
sockets.warnDeprecated(socket, 'PUT /api/v1/topics/:tid/follow');
|
||||
await followCommand(topics.follow, socket, tid);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user