mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
* WIP * more unread work * faster teaser block handling if user doesn't have anyone blocked don't check * much faster filtering of blocked posts * add missing uid * add tidsByFilter to return * dont load all pids to find previous non-blocked teaser * fix unread filters they no longer use unread/new unread/watched etc they are query strings now * shorter nav item code * add unreplied to filters fix icons not clearing to 0 dont increment unread counters if there is a reply in a topic where you ignored the topic creator
This commit is contained in:
committed by
GitHub
parent
df4f5f6f27
commit
cf75c79611
@@ -5,6 +5,7 @@ var async = require('async');
|
||||
var _ = require('lodash');
|
||||
var winston = require('winston');
|
||||
|
||||
var db = require('../database');
|
||||
var meta = require('../meta');
|
||||
var user = require('../user');
|
||||
var posts = require('../posts');
|
||||
@@ -112,53 +113,54 @@ module.exports = function (Topics) {
|
||||
};
|
||||
|
||||
function handleBlocks(uid, teasers, callback) {
|
||||
async.mapSeries(teasers, function (postData, nextPost) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.blocks.is(postData.uid, uid, next);
|
||||
},
|
||||
function (isBlocked, next) {
|
||||
if (!isBlocked) {
|
||||
return nextPost(null, postData);
|
||||
}
|
||||
getPreviousNonBlockedPost(postData, uid, next);
|
||||
},
|
||||
], nextPost);
|
||||
}, callback);
|
||||
user.blocks.list(uid, function (err, blockedUids) {
|
||||
if (err || !blockedUids.length) {
|
||||
return callback(err, teasers);
|
||||
}
|
||||
async.mapSeries(teasers, function (postData, nextPost) {
|
||||
if (blockedUids.includes(parseInt(postData.uid, 10))) {
|
||||
getPreviousNonBlockedPost(postData, blockedUids, nextPost);
|
||||
} else {
|
||||
setImmediate(nextPost, null, postData);
|
||||
}
|
||||
}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getPreviousNonBlockedPost(postData, uid, callback) {
|
||||
function getPreviousNonBlockedPost(postData, blockedUids, callback) {
|
||||
let isBlocked = false;
|
||||
let prevPost = postData;
|
||||
Topics.getPids(postData.tid, function (err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
const postsPerIteration = 5;
|
||||
let start = 0;
|
||||
let stop = start + postsPerIteration - 1;
|
||||
|
||||
async.doWhilst(function (next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
const index = pids.lastIndexOf(String(prevPost.pid));
|
||||
if (index <= 0) {
|
||||
return callback(null, null);
|
||||
}
|
||||
async.doWhilst(function (next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRevRange('tid:' + postData.tid + ':posts', start, stop, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
if (!pids.length) {
|
||||
return callback(null, null);
|
||||
}
|
||||
|
||||
posts.getPostFields(pids[index - 1], ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
|
||||
},
|
||||
function (_prevPost, next) {
|
||||
prevPost = _prevPost;
|
||||
user.blocks.is(prevPost.uid, uid, next);
|
||||
},
|
||||
function (_isBlocked, next) {
|
||||
isBlocked = _isBlocked;
|
||||
next();
|
||||
},
|
||||
], next);
|
||||
}, function () {
|
||||
return isBlocked && prevPost && prevPost.pid;
|
||||
}, function (err) {
|
||||
callback(err, prevPost);
|
||||
});
|
||||
posts.getPostsFields(pids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
|
||||
},
|
||||
function (prevPosts, next) {
|
||||
isBlocked = prevPosts.every(function (post) {
|
||||
const isPostBlocked = blockedUids.includes(parseInt(post.uid, 10));
|
||||
prevPost = !isPostBlocked ? post : prevPost;
|
||||
return isPostBlocked;
|
||||
});
|
||||
start += postsPerIteration;
|
||||
stop = start + postsPerIteration - 1;
|
||||
next();
|
||||
},
|
||||
], next);
|
||||
}, function () {
|
||||
return isBlocked && prevPost && prevPost.pid;
|
||||
}, function (err) {
|
||||
callback(err, prevPost);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user