From 08c1dad3ee5867930c247448ffc1998c49100a2d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 12 Jan 2015 16:57:18 -0500 Subject: [PATCH] topics.isFollowing works with multiple tids now --- public/language/en_GB/global.json | 3 ++- public/src/ajaxify.js | 2 +- public/src/app.js | 3 ++- src/threadTools.js | 6 +++--- src/topics.js | 4 ++-- src/topics/follow.js | 12 +++++++++--- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json index 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.js index 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.js index 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.js index 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.js index 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.js index 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) {