From 4f6cc204579c88fee3282585cc62786b2c42a023 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 20 Apr 2018 14:48:10 -0400 Subject: [PATCH] completed basic integration for #6463 --- src/controllers/unread.js | 6 ++++++ src/messaging.js | 9 +++++++++ src/topics/recent.js | 12 +++++++++++- src/user/blocks.js | 5 +---- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/controllers/unread.js b/src/controllers/unread.js index b4b8e23f38..d7de3d8e91 100644 --- a/src/controllers/unread.js +++ b/src/controllers/unread.js @@ -54,6 +54,12 @@ unreadController.get = function (req, res, next) { cutoff: cutoff, }, next); }, + function (data, next) { + user.blocks.filter(req.uid, data.topics, function (err, filtered) { + data.topics = filtered; + next(err, data); + }); + }, function (data) { data.title = meta.config.homePageTitle || '[[pages:home]]'; data.pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage)); diff --git a/src/messaging.js b/src/messaging.js index 6b0462eb0e..7267e16a9e 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -219,6 +219,15 @@ Messaging.getTeaser = function (uid, roomId, callback) { } Messaging.getMessageFields(mids[0], ['fromuid', 'content', 'timestamp'], next); }, + function (teaser, next) { + user.blocks.is(teaser.fromuid, uid, function (err, blocked) { + if (err || blocked) { + return callback(err); + } + + next(null, teaser); + }); + }, function (_teaser, next) { teaser = _teaser; if (!teaser) { diff --git a/src/topics/recent.js b/src/topics/recent.js index 2e77262d44..30da085deb 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -77,10 +77,20 @@ module.exports = function (Topics) { user.getIgnoredCategories(uid, next); }, topicData: function (next) { - Topics.getTopicsFields(tids, ['tid', 'cid'], next); + Topics.getTopicsFields(tids, ['uid', 'tid', 'cid'], next); }, }, next); }, + function (results, next) { + user.blocks.filter(uid, results.topicData, function (err, filtered) { + if (err) { + return next(err); + } + + results.topicData = filtered; + next(null, results); + }); + }, function (results, next) { cid = cid && cid.map(String); tids = results.topicData.filter(function (topic) { diff --git a/src/user/blocks.js b/src/user/blocks.js index bd4879136f..093ea518f3 100644 --- a/src/user/blocks.js +++ b/src/user/blocks.js @@ -29,9 +29,6 @@ module.exports = function (User) { return callback(err); } - // for debugging - // blocked = [2]; - blocked = blocked.map(uid => parseInt(uid, 10)).filter(Boolean); User.blocks._cache.set(uid, blocked); callback(null, blocked); @@ -61,6 +58,7 @@ module.exports = function (User) { }; User.blocks.filter = function (uid, property, set, callback) { + // Given whatever is passed in, iterates through it, and removes entries made by blocked uids // property is optional if (Array.isArray(property) && typeof set === 'function' && !callback) { callback = set; @@ -68,7 +66,6 @@ module.exports = function (User) { property = 'uid'; } - // Given whatever is passed in, iterates through it, and removes entries made by blocked uids if (!Array.isArray(set) || !(set[0].hasOwnProperty(property) || typeof set[0] === 'number' || typeof set[0] === 'string')) { return callback(null, set); }