mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-25 02:31:16 +02:00
topics.isFollowing works with multiple tids now
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -14,11 +14,17 @@ var async = require('async'),
|
||||
module.exports = function(Topics) {
|
||||
|
||||
|
||||
Topics.isFollowing = function(tid, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, false);
|
||||
Topics.isFollowing = function(tids, uid, callback) {
|
||||
if (!Array.isArray(tids)) {
|
||||
return callback();
|
||||
}
|
||||
db.isSetMember('tid:' + tid + ':followers', uid, callback);
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, tids.map(function() { return false; }));
|
||||
}
|
||||
var keys = tids.map(function(tid) {
|
||||
return 'tid:' + tid + ':followers';
|
||||
})
|
||||
db.isMemberOfSets(keys, uid, callback);
|
||||
};
|
||||
|
||||
Topics.getFollowers = function(tid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user