mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 10:35:55 +01:00
better filtering
if topic is followed but category ignored show it in unread
This commit is contained in:
@@ -55,8 +55,8 @@
|
|||||||
"reading": "Reading",
|
"reading": "Reading",
|
||||||
"ignoring": "Ignoring",
|
"ignoring": "Ignoring",
|
||||||
"following.description": "Notify me of new replies",
|
"following.description": "Notify me of new replies",
|
||||||
"reading.description": "Show topic in unread list",
|
"reading.description": "Show topic in unread",
|
||||||
"ignoring.description": "Do not show topic in unread list",
|
"ignoring.description": "Do not show topic in unread",
|
||||||
|
|
||||||
"thread_tools.title": "Topic Tools",
|
"thread_tools.title": "Topic Tools",
|
||||||
"thread_tools.markAsUnreadForAll": "Mark Unread",
|
"thread_tools.markAsUnreadForAll": "Mark Unread",
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ var async = require('async');
|
|||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
var S = require('string');
|
var S = require('string');
|
||||||
|
|
||||||
|
var db = require('../database');
|
||||||
var websockets = require('./index');
|
var websockets = require('./index');
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var posts = require('../posts');
|
var posts = require('../posts');
|
||||||
var topics = require('../topics');
|
var topics = require('../topics');
|
||||||
var categories = require('../categories');
|
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
var notifications = require('../notifications');
|
var notifications = require('../notifications');
|
||||||
var plugins = require('../plugins');
|
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);
|
privileges.topics.filterUids('read', result.posts[0].topic.tid, uids, next);
|
||||||
},
|
},
|
||||||
function(uids, next) {
|
function(uids, next) {
|
||||||
topics.filterIgnoringUids(result.posts[0].topic.tid, uids, next);
|
filterTidCidIgnorers(uids, result.posts[0].topic.tid, result.posts[0].topic.cid, next);
|
||||||
},
|
|
||||||
function(uids, next) {
|
|
||||||
categories.filterIgnoringUids(result.posts[0].topic.cid, 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);
|
||||||
@@ -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) {
|
SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||||
if (!pid || !fromuid || !notification) {
|
if (!pid || !fromuid || !notification) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ module.exports = function(Topics) {
|
|||||||
|
|
||||||
tids = tids.slice(0, 200);
|
tids = tids.slice(0, 200);
|
||||||
|
|
||||||
filterTopics(uid, tids, cid, ignoredCids, next);
|
filterTopics(uid, tids, cid, ignoredCids, filter, next);
|
||||||
}
|
}
|
||||||
], callback);
|
], 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) {
|
if (!Array.isArray(ignoredCids) || !tids.length) {
|
||||||
return callback(null, tids);
|
return callback(null, tids);
|
||||||
}
|
}
|
||||||
@@ -171,11 +171,24 @@ module.exports = function(Topics) {
|
|||||||
privileges.topics.filterTids('read', tids, uid, next);
|
privileges.topics.filterTids('read', tids, uid, next);
|
||||||
},
|
},
|
||||||
function(tids, next) {
|
function(tids, next) {
|
||||||
|
async.parallel({
|
||||||
|
topics: function(next) {
|
||||||
Topics.getTopicsFields(tids, ['tid', 'cid'], next);
|
Topics.getTopicsFields(tids, ['tid', 'cid'], next);
|
||||||
},
|
},
|
||||||
function(topics, next) {
|
isTopicsFollowed: function(next) {
|
||||||
tids = topics.filter(function(topic) {
|
if (filter === 'watched' || filter === 'new') {
|
||||||
return topic && topic.cid && ignoredCids.indexOf(topic.cid.toString()) === -1 && (!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
|
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) {
|
}).map(function(topic) {
|
||||||
return topic.tid;
|
return topic.tid;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user