feat(writeapi): topic follow/ignore

This commit is contained in:
Julian Lam
2020-10-06 11:36:52 -04:00
parent da25ce4d09
commit 9be5629458
4 changed files with 42 additions and 16 deletions

View File

@@ -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;