better filtering

if topic is followed but category ignored show it in unread
v1.18.x
barisusakli 9 years ago
parent 7a044b4978
commit 11d3834eb9

@ -55,8 +55,8 @@
"reading": "Reading",
"ignoring": "Ignoring",
"following.description": "Notify me of new replies",
"reading.description": "Show topic in unread list",
"ignoring.description": "Do not show topic in unread list",
"reading.description": "Show topic in unread",
"ignoring.description": "Do not show topic in unread",
"thread_tools.title": "Topic Tools",
"thread_tools.markAsUnreadForAll": "Mark Unread",

@ -4,11 +4,11 @@ var async = require('async');
var winston = require('winston');
var S = require('string');
var db = require('../database');
var websockets = require('./index');
var user = require('../user');
var posts = require('../posts');
var topics = require('../topics');
var categories = require('../categories');
var privileges = require('../privileges');
var notifications = require('../notifications');
var plugins = require('../plugins');
@ -29,10 +29,7 @@ SocketHelpers.notifyNew = function(uid, type, result) {
privileges.topics.filterUids('read', result.posts[0].topic.tid, uids, next);
},
function(uids, next) {
topics.filterIgnoringUids(result.posts[0].topic.tid, uids, next);
},
function(uids, next) {
categories.filterIgnoringUids(result.posts[0].topic.cid, uids, next);
filterTidCidIgnorers(uids, result.posts[0].topic.tid, result.posts[0].topic.cid, next);
},
function(uids, next) {
plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: uid, type: type}, next);
@ -55,6 +52,31 @@ SocketHelpers.notifyNew = function(uid, type, result) {
});
};
function filterTidCidIgnorers(uids, tid, cid, callback) {
async.waterfall([
function (next) {
async.parallel({
topicFollowed: function(next) {
db.isSetMembers('tid:' + tid + ':followers', uids, next);
},
topicIgnored: function(next) {
db.isSetMembers('tid:' + tid + ':ignorers', uids, next);
},
categoryIgnored: function(next) {
db.sortedSetScores('cid:' + cid + ':ignorers', uids, next);
}
}, next);
},
function (results, next) {
uids = uids.filter(function(uid, index) {
return results.topicFollowed[index] ||
(!results.topicFollowed[index] && !results.topicIgnored[index] && !results.categoryIgnored[index]);
});
next(null, uids);
}
], callback);
}
SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification) {
if (!pid || !fromuid || !notification) {
return;

@ -144,7 +144,7 @@ module.exports = function(Topics) {
tids = tids.slice(0, 200);
filterTopics(uid, tids, cid, ignoredCids, next);
filterTopics(uid, tids, cid, ignoredCids, filter, next);
}
], callback);
};
@ -161,7 +161,7 @@ module.exports = function(Topics) {
});
}
function filterTopics(uid, tids, cid, ignoredCids, callback) {
function filterTopics(uid, tids, cid, ignoredCids, filter, callback) {
if (!Array.isArray(ignoredCids) || !tids.length) {
return callback(null, tids);
}
@ -171,11 +171,24 @@ module.exports = function(Topics) {
privileges.topics.filterTids('read', tids, uid, next);
},
function(tids, next) {
async.parallel({
topics: function(next) {
Topics.getTopicsFields(tids, ['tid', 'cid'], next);
},
function(topics, next) {
tids = topics.filter(function(topic) {
return topic && topic.cid && ignoredCids.indexOf(topic.cid.toString()) === -1 && (!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
isTopicsFollowed: function(next) {
if (filter === 'watched' || filter === 'new') {
return next(null, []);
}
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
}
}, next);
},
function(results, next) {
var topics = results.topics;
tids = topics.filter(function(topic, index) {
return topic && topic.cid &&
(!!results.isTopicsFollowed[index] || ignoredCids.indexOf(topic.cid.toString()) === -1) &&
(!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
}).map(function(topic) {
return topic.tid;
});

Loading…
Cancel
Save