Node.js based forum software built for the modern web
topics.isFollowing works with multiple tids now
barisusakli08c1dad3ee58
diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.jsonindex a373c7a4d3..78998f6f0e 100644--- a/public/language/en_GB/global.json+++ b/public/language/en_GB/global.json@@ -98,6 +98,7 @@"updated.message": "This forum has just been updated to the latest version. Click here to refresh the page.","privacy": "Privacy",-+ "follow": "Follow",+ "unfollow": "Unfollow","delete_all": "Delete All"}diff --git a/public/src/ajaxify.js b/public/src/ajaxify.jsindex 8a5fa5b4fa..d53c89b651 100644--- a/public/src/ajaxify.js+++ b/public/src/ajaxify.js@@ -115,7 +115,7 @@ $(document).ready(function() {ajaxify.variables.parse();ajaxify.widgets.render(tpl_url, url, function() {- $(window).trigger('action:ajaxify.end', {url: url});+ $(window).trigger('action:ajaxify.end', {url: url, tpl_url: tpl_url});});$(window).trigger('action:ajaxify.contentLoaded', {url: url});diff --git a/public/src/app.js b/public/src/app.jsindex a77200fdd9..a3d8fa62ca 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -539,7 +539,8 @@ app.uid = null;ajaxify.widgets.render(tpl_url, url, function() {app.processPage();$window.trigger('action:ajaxify.end', {- url: url+ url: url,+ tpl_url: tpl_url});});});diff --git a/src/threadTools.js b/src/threadTools.jsindex 8e622ce4a0..74b316f987 100644--- a/src/threadTools.js+++ b/src/threadTools.js@@ -239,11 +239,11 @@ var winston = require('winston'),if (!exists) {return next(new Error('[[error:no-topic]]'));}- topics.isFollowing(tid, uid, next);+ topics.isFollowing([tid], uid, next);},function (isFollowing, next) {- db[isFollowing ? 'setRemove' : 'setAdd']('tid:' + tid + ':followers', uid, function(err) {- next(err, !isFollowing);+ db[isFollowing[0] ? 'setRemove' : 'setAdd']('tid:' + tid + ':followers', uid, function(err) {+ next(err, !isFollowing[0]);});}], callback);diff --git a/src/topics.js b/src/topics.jsindex a296bb1a30..d7b1b04c7d 100644--- a/src/topics.js+++ b/src/topics.js@@ -234,7 +234,7 @@ var async = require('async'),category: async.apply(Topics.getCategoryData, tid),threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', []),tags: async.apply(Topics.getTopicTagsObjects, tid),- isFollowing: async.apply(Topics.isFollowing, tid, uid)+ isFollowing: async.apply(Topics.isFollowing, [tid], uid)}, function(err, results) {if (err) {return callback(err);@@ -244,7 +244,7 @@ var async = require('async'),topicData.category = results.category;topicData.thread_tools = results.threadTools;topicData.tags = results.tags;- topicData.isFollowing = results.isFollowing;+ topicData.isFollowing = results.isFollowing[0];topicData.unreplied = parseInt(topicData.postcount, 10) === 1;topicData.deleted = parseInt(topicData.deleted, 10) === 1;diff --git a/src/topics/follow.js b/src/topics/follow.jsindex 6a0e2b97f8..b79e513c07 100644--- a/src/topics/follow.js+++ b/src/topics/follow.js@@ -14,11 +14,17 @@ var async = require('async'),module.exports = function(Topics) {- Topics.isFollowing = function(tid, uid, callback) {+ Topics.isFollowing = function(tids, uid, callback) {+ if (!Array.isArray(tids)) {+ return callback();+ }if (!parseInt(uid, 10)) {- return callback(null, false);+ return callback(null, tids.map(function() { return false; }));}- db.isSetMember('tid:' + tid + ':followers', uid, callback);+ var keys = tids.map(function(tid) {+ return 'tid:' + tid + ':followers';+ })+ db.isMemberOfSets(keys, uid, callback);};Topics.getFollowers = function(tid, callback) {