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