Unread changes closes #6781 (#6783)

* 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:
Barış Soner Uşaklı
2018-09-24 12:58:59 -04:00
committed by GitHub
parent df4f5f6f27
commit cf75c79611
7 changed files with 287 additions and 191 deletions

View File

@@ -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);
});
}