Skip to content

Node.js based forum software built for the modern web

watch unwatch

barisusakli5f55cc947ceb
diff --git a/public/language/en_GB/topic.json b/public/language/en_GB/topic.json
index de892fb800..e837ba664d 100644
--- a/public/language/en_GB/topic.json
+++ b/public/language/en_GB/topic.json
@@ -43,7 +43,9 @@
"markAsUnreadForAll.success" : "Topic marked as unread for all.",
"watch": "Watch",
+ "unwatch": "Unwatch",
"watch.title": "Be notified of new replies in this topic",
+ "unwatch.title": "Stop watching this topic",
"share_this_post": "Share this Post",
"thread_tools.title": "Topic Tools",
diff --git a/public/src/forum/topic/threadTools.js b/public/src/forum/topic/threadTools.js
index 1e8e63b14f..f72705bd02 100644
--- a/public/src/forum/topic/threadTools.js
+++ b/public/src/forum/topic/threadTools.js
@@ -60,10 +60,6 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
fork.init();
- socket.emit('topics.followCheck', tid, function(err, state) {
- setFollowState(state);
- });
-
$('.posts').on('click', '.follow', function() {
socket.emit('topics.follow', tid, function(err, state) {
if(err) {
@@ -149,10 +145,23 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
});
$('.topic-title i.fa-thumb-tack').toggleClass('hide', !data.isPinned);
}
- }
+ };
function setFollowState(state) {
- $('.posts .follow').toggleClass('btn-success', state).attr('title', state ? 'You are currently receiving updates to this topic' : 'Be notified of new replies in this topic');
+ var title = state ? '[[topic:unwatch.title]]' : '[[topic:watch.title]]';
+ var iconClass = state ? 'fa fa-eye-slash' : 'fa fa-eye';
+ var text = state ? '[[topic:unwatch]]' : '[[topic:watch]]';
+
+ var followEl = $('.posts .follow');
+
+ translator.translate(title, function(titleTranslated) {
+ followEl.attr('title', titleTranslated).find('i').attr('class', iconClass);
+ followEl.find('span').text(text);
+
+ translator.translate(followEl.html(), function(translated) {
+ followEl.html(translated);
+ });
+ });
}
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index 19de9251f0..75316419d6 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -199,7 +199,6 @@ Sockets.init = function(server) {
});
socket.on('*', function(payload, callback) {
-
function callMethod(method) {
method.call(null, socket, payload.args.length ? payload.args[0] : null, function(err, result) {
if (callback) {
@@ -279,10 +278,7 @@ Sockets.uidInRoom = function(uid, room) {
Sockets.getSocketCount = function() {
var clients = io.sockets.manager.rooms[''];
- if (!Array.isArray(clients)) {
- return 0;
- }
- return clients.length;
+ return Array.isArray(clients) ? clients.length : 0;
};
Sockets.getConnectedClients = function() {
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index 7b7b0fb7f2..754cf6991f 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -395,10 +395,6 @@ SocketTopics.moveAll = function(socket, data, callback) {
});
};
-SocketTopics.followCheck = function(socket, tid, callback) {
- topics.isFollowing(tid, socket.uid, callback);
-};
-
SocketTopics.follow = function(socket, tid, callback) {
if(!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
diff --git a/src/topics.js b/src/topics.js
index 74f9cbd945..da8ffb4776 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -286,17 +286,21 @@ var async = require('async'),
},
tags: function(next) {
Topics.getTopicTagsObjects(tid, next);
+ },
+ isFollowing: function(next) {
+ Topics.isFollowing(tid, uid, next);
}
}, function(err, results) {
if (err) {
return callback(err);
}
- topicData.category = results.category;
topicData.posts = results.posts;
- topicData.tags = results.tags;
+ topicData.category = results.category;
topicData.thread_tools = results.threadTools;
- topicData.pageCount = results.pageCount;
+ topicData.tags = results.tags;
+ topicData.isFollowing = results.isFollowing;
+
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
topicData.locked = parseInt(topicData.locked, 10) === 1;