-moved user.blocks.filter from unread controller to getUnreadTopics so
topics are filtered at other places this function is called
- when a new post is made do not send it to uids that have blocked the
poster
- update getUnreadTids so it does not return topics that have new posts
from blocked users
- update hasReadTopics so it does not return false data if topic has new
posts from blocked users
v1.18.x
Barış Soner Uşaklı
parent 0c9907367a
commit b43bfa3d5b

@ -54,12 +54,6 @@ unreadController.get = function (req, res, next) {
cutoff: cutoff, cutoff: cutoff,
}, next); }, next);
}, },
function (data, next) {
user.blocks.filter(req.uid, data.topics, function (err, filtered) {
data.topics = filtered;
next(err, data);
});
},
function (data) { function (data) {
data.title = meta.config.homePageTitle || '[[pages:home]]'; data.title = meta.config.homePageTitle || '[[pages:home]]';
data.pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage)); data.pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));

@ -31,6 +31,9 @@ SocketHelpers.notifyNew = function (uid, type, result) {
function (uids, next) { function (uids, next) {
filterTidCidIgnorers(uids, result.posts[0].topic.tid, result.posts[0].topic.cid, next); filterTidCidIgnorers(uids, result.posts[0].topic.tid, result.posts[0].topic.cid, next);
}, },
function (uids, next) {
user.blocks.filterUids(uid, uids, next);
},
function (uids, next) { function (uids, next) {
plugins.fireHook('filter:sockets.sendNewPostToUids', { uidsTo: uids, uidFrom: uid, type: type }, next); plugins.fireHook('filter:sockets.sendNewPostToUids', { uidsTo: uids, uidFrom: uid, type: type }, next);
}, },

@ -6,6 +6,7 @@ var _ = require('lodash');
var db = require('../database'); var db = require('../database');
var user = require('../user'); var user = require('../user');
var posts = require('../posts');
var notifications = require('../notifications'); var notifications = require('../notifications');
var categories = require('../categories'); var categories = require('../categories');
var privileges = require('../privileges'); var privileges = require('../privileges');
@ -150,7 +151,6 @@ module.exports = function (Topics) {
], callback); ], callback);
}; };
function filterTopics(uid, tids, cid, filter, callback) { function filterTopics(uid, tids, cid, filter, callback) {
if (!tids.length) { if (!tids.length) {
return callback(null, tids); return callback(null, tids);
@ -181,15 +181,53 @@ module.exports = function (Topics) {
}, },
function (results, next) { function (results, next) {
var topics = results.topics; var topics = results.topics;
cid = cid && cid.map(String); cid = cid && cid.map(String);
tids = topics.filter(function (topic, index) { topics = topics.filter(function (topic, index) {
return topic && topic.cid && return topic && topic.cid &&
(!!results.isTopicsFollowed[index] || results.ignoredCids.indexOf(topic.cid.toString()) === -1) && (!!results.isTopicsFollowed[index] || results.ignoredCids.indexOf(topic.cid.toString()) === -1) &&
(!cid || (cid.length && cid.indexOf(String(topic.cid)) !== -1)); (!cid || (cid.length && cid.indexOf(String(topic.cid)) !== -1));
}).map(function (topic) {
return topic.tid;
}); });
next(null, tids);
user.blocks.filter(uid, topics, next);
},
function (filteredTopics, next) {
tids = filteredTopics.map(function (topic) {
return topic && topic.tid;
});
filterTidsThatHaveBlockedPosts(uid, tids, next);
},
], callback);
}
function filterTidsThatHaveBlockedPosts(uid, tids, callback) {
async.filter(tids, function (tid, next) {
doesTidHaveUnblockedUnreadPosts(uid, tid, next);
}, callback);
}
function doesTidHaveUnblockedUnreadPosts(uid, tid, callback) {
async.waterfall([
function (next) {
db.sortedSetScore('uid:' + uid + ':tids_read', tid, next);
},
function (userLastReadTimestamp, next) {
if (!userLastReadTimestamp) {
return callback(null, true);
}
db.getSortedSetRevRangeByScore('tid:' + tid + ':posts', 0, -1, '+inf', userLastReadTimestamp, next);
},
function (pidsSinceLastVisit, next) {
if (!pidsSinceLastVisit.length) {
return callback(null, false);
}
posts.getPostsFields(pidsSinceLastVisit, ['pid', 'uid'], next);
},
function (postData, next) {
user.blocks.filter(uid, postData, next);
},
function (unreadPosts, next) {
next(null, unreadPosts.length > 0);
}, },
], callback); ], callback);
} }
@ -347,12 +385,26 @@ module.exports = function (Topics) {
function (results, next) { function (results, next) {
var cutoff = Topics.unreadCutoff(); var cutoff = Topics.unreadCutoff();
var result = tids.map(function (tid, index) { var result = tids.map(function (tid, index) {
return !results.tids_unread[index] && var read = !results.tids_unread[index] &&
(results.recentScores[index] < cutoff || (results.recentScores[index] < cutoff ||
!!(results.userScores[index] && results.userScores[index] >= results.recentScores[index])); !!(results.userScores[index] && results.userScores[index] >= results.recentScores[index]));
return { tid: tid, read: read };
}); });
next(null, result); async.map(result, function (data, next) {
if (data.read) {
return next(null, true);
}
doesTidHaveUnblockedUnreadPosts(uid, data.tid, function (err, hasUnblockedUnread) {
if (err) {
return next(err);
}
if (!hasUnblockedUnread) {
data.read = true;
}
next(null, data.read);
});
}, next);
}, },
], callback); ], callback);
}; };

Loading…
Cancel
Save