diff --git a/src/categories.js b/src/categories.js index 4458e09481..5bb5222d38 100644 --- a/src/categories.js +++ b/src/categories.js @@ -350,11 +350,11 @@ var privileges = require('./privileges'); Categories.filterIgnoringUids = function (cid, uids, callback) { async.waterfall([ function (next) { - db.sortedSetScores('cid:' + cid + ':ignorers', uids, next); + db.isSortedSetMembers('cid:' + cid + ':ignorers', uids, next); }, - function (scores, next) { + function (isIgnoring, next) { var readingUids = uids.filter(function (uid, index) { - return uid && !!scores[index]; + return uid && !isIgnoring[index]; }); next(null, readingUids); } diff --git a/src/topics/follow.js b/src/topics/follow.js index 0667218588..4775cdb9bc 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -153,9 +153,9 @@ module.exports = function (Topics) { function (next) { db.isSetMembers('tid:' + tid + ':ignorers', uids, next); }, - function (isMembers, next) { + function (isIgnoring, next) { var readingUids = uids.filter(function (uid, index) { - return uid && isMembers[index]; + return uid && !isIgnoring[index]; }); next(null, readingUids); } diff --git a/test/topics.js b/test/topics.js index 3a192b9e94..24b4c973de 100644 --- a/test/topics.js +++ b/test/topics.js @@ -445,7 +445,7 @@ describe('Topic\'s', function () { assert.equal(pinnedTids[1], tid2); done(); }); - }); + }); }); }); @@ -1197,8 +1197,65 @@ describe('Topic\'s', function () { }); }); }); + }); + describe('follow/unfollow', function () { + var socketTopics = require('../src/socket.io/topics'); + var tid; + var followerUid; + before(function (done) { + User.create({username: 'follower'}, function (err, uid) { + if (err) { + return done(err); + } + followerUid = uid; + topics.post({uid: adminUid, title: 'topic title', content: 'some content', cid: topic.categoryId}, function (err, result) { + if (err) { + return done(err); + } + tid = result.topicData.tid; + done(); + }); + }); + }); + it('should filter ignoring uids', function (done) { + socketTopics.changeWatching({uid: followerUid}, {tid: tid, type: 'ignore'}, function (err) { + assert.ifError(err); + topics.filterIgnoringUids(tid, [adminUid, followerUid], function (err, uids) { + assert.ifError(err); + assert.equal(uids.length, 1); + assert.equal(uids[0], adminUid); + done(); + }); + }); + }); + + it('should error with invalid data', function (done) { + socketTopics.changeWatching({uid: followerUid}, {}, function (err) { + assert.equal(err.message, '[[error:invalid-data]]'); + done(); + }); + }) + + it('should error with invalid type', function (done) { + socketTopics.changeWatching({uid: followerUid}, {tid: tid, type: 'derp'}, function (err) { + assert.equal(err.message, '[[error:invalid-command]]'); + done(); + }); + }) + + it('should follow topic', function (done) { + topics.toggleFollow(tid, followerUid, function(err, isFollowing) { + assert.ifError(err); + assert(isFollowing); + topics.isFollowing([tid], followerUid, function (err, isFollowing) { + assert.ifError(err); + assert(isFollowing); + done(); + }); + }); + }); });