Node.js based forum software built for the modern web
better filtering
barisusakli11d3834eb90b
diff --git a/public/language/en_GB/topic.json b/public/language/en_GB/topic.jsonindex a64bd15ca7..176e9daa52 100644--- a/public/language/en_GB/topic.json+++ b/public/language/en_GB/topic.json@@ -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",diff --git a/src/socket.io/helpers.js b/src/socket.io/helpers.jsindex 148420dfb9..68182293f4 100644--- a/src/socket.io/helpers.js+++ b/src/socket.io/helpers.js@@ -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;diff --git a/src/topics/unread.js b/src/topics/unread.jsindex c62ae5ac3a..b4900be3a1 100644--- a/src/topics/unread.js+++ b/src/topics/unread.js@@ -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) {- Topics.getTopicsFields(tids, ['tid', 'cid'], next);+ async.parallel({+ topics: function(next) {+ Topics.getTopicsFields(tids, ['tid', 'cid'], next);+ },+ isTopicsFollowed: function(next) {+ if (filter === 'watched' || filter === 'new') {+ return next(null, []);+ }+ db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);+ }+ }, 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));+ 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;});