Skip to content

Node.js based forum software built for the modern web

add tests for blocked users teaser/unread

Barış Soner Uşaklıc06480b82e1e
diff --git a/src/topics/teaser.js b/src/topics/teaser.js
index 2a636b0702..a5dafcaaa1 100644
--- a/src/topics/teaser.js
+++ b/src/topics/teaser.js
@@ -133,17 +133,23 @@ module.exports = function (Topics) {
const postsPerIteration = 5;
let start = 0;
let stop = start + postsPerIteration - 1;
-
+ let checkedAllReplies = false;
async.doWhilst(function (next) {
async.waterfall([
function (next) {
db.getSortedSetRevRange('tid:' + postData.tid + ':posts', start, stop, next);
},
function (pids, next) {
- if (!pids.length) {
- return callback(null, null);
+ if (pids.length) {
+ return next(null, pids);
}
+ checkedAllReplies = true;
+ Topics.getTopicField(postData.tid, 'mainPid', function (err, mainPid) {
+ next(err, [mainPid]);
+ });
+ },
+ function (pids, next) {
posts.getPostsFields(pids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
},
function (prevPosts, next) {
@@ -158,7 +164,7 @@ module.exports = function (Topics) {
},
], next);
}, function () {
- return isBlocked && prevPost && prevPost.pid;
+ return isBlocked && prevPost && prevPost.pid && !checkedAllReplies;
}, function (err) {
callback(err, prevPost);
});
diff --git a/src/topics/unread.js b/src/topics/unread.js
index c8b3552af5..3a2ee3ed20 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -213,6 +213,7 @@ module.exports = function (Topics) {
}
if (topic && topic.cid && cidMatch(topic.cid) && !blockedUids.includes(parseInt(topic.uid, 10))) {
+ topic.tid = parseInt(topic.tid, 10);
if ((results.isTopicsFollowed[index] || !results.ignoredCids.includes(String(topic.cid)))) {
counts[''] += 1;
tidsByFilter[''].push(topic.tid);
diff --git a/test/topics.js b/test/topics.js
index f8e4e95087..488f78b7aa 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -1350,6 +1350,34 @@ describe('Topic\'s', function () {
},
], done);
});
+
+ it('should not return topic as unread if new post is from blocked user', function (done) {
+ var blockedUid;
+ var topic;
+ async.waterfall([
+ function (next) {
+ topics.post({ uid: adminUid, title: 'will not get as unread', content: 'not unread', cid: categoryObj.cid }, next);
+ },
+ function (result, next) {
+ topic = result.topicData;
+ User.create({ username: 'blockedunread' }, next);
+ },
+ function (uid, next) {
+ blockedUid = uid;
+ User.blocks.add(uid, adminUid, next);
+ },
+ function (next) {
+ topics.reply({ uid: blockedUid, content: 'post from blocked user', tid: topic.tid }, next);
+ },
+ function (result, next) {
+ topics.getUnreadTids({ cid: 0, uid: adminUid }, next);
+ },
+ function (unreadTids, next) {
+ assert(!unreadTids.includes(parseInt(topic.tid, 10)));
+ User.blocks.remove(blockedUid, adminUid, next);
+ },
+ ], done);
+ });
});
describe('tags', function () {
@@ -1775,7 +1803,7 @@ describe('Topic\'s', function () {
});
});
- it('should get teasers with first posts', function (done) {
+ it('should get teasers with last posts', function (done) {
meta.config.teaserPost = 'last-post';
topics.reply({ uid: adminUid, content: 'reply 1 content', tid: topic1.topicData.tid }, function (err, result) {
assert.ifError(err);
@@ -1816,6 +1844,29 @@ describe('Topic\'s', function () {
done();
});
});
+
+ it('should not return teaser if user is blocked', function (done) {
+ var blockedUid;
+ async.waterfall([
+ function (next) {
+ User.create({ username: 'blocked' }, next);
+ },
+ function (uid, next) {
+ blockedUid = uid;
+ User.blocks.add(uid, adminUid, next);
+ },
+ function (next) {
+ topics.reply({ uid: blockedUid, content: 'post from blocked user', tid: topic2.topicData.tid }, next);
+ },
+ function (result, next) {
+ topics.getTeaser(topic2.topicData.tid, adminUid, next);
+ },
+ function (teaser, next) {
+ assert.equal(teaser.content, 'content 2');
+ User.blocks.remove(blockedUid, adminUid, next);
+ },
+ ], done);
+ });
});
describe('tag privilege', function () {