mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
unreadTids
This commit is contained in:
@@ -34,6 +34,6 @@ helpers.valueToString = function(value) {
|
||||
|
||||
helpers.noop = function() {};
|
||||
|
||||
helpers.KEY_LIMIT = 100;
|
||||
helpers.KEY_LIMIT = 300;
|
||||
|
||||
module.exports = helpers;
|
||||
@@ -196,15 +196,17 @@
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
groupNames = internals.removeEphemeralGroups(groupNames);
|
||||
if (groupNames.length === 0) {
|
||||
return callback(null, null);
|
||||
}
|
||||
|
||||
var results = [];
|
||||
uids.forEach(function() {
|
||||
results.push(false);
|
||||
});
|
||||
|
||||
groupNames = internals.removeEphemeralGroups(groupNames);
|
||||
if (groupNames.length === 0) {
|
||||
return callback(null, results);
|
||||
}
|
||||
|
||||
async.each(groupNames, function(groupName, next) {
|
||||
Groups.isMembers(uids, groupName, function(err, isMembers) {
|
||||
if (err) {
|
||||
|
||||
@@ -46,9 +46,10 @@ SocketTopics.post = function(socket, data, callback) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i=0; i<uids.length; ++i) {
|
||||
if (parseInt(uids[i], 10) !== socket.uid) {
|
||||
websockets.in('uid_' + uids[i]).emit('event:new_post', result.postData);
|
||||
websockets.in('uid_' + uids[i]).emit('event:new_post', {posts: result.postData});
|
||||
websockets.in('uid_' + uids[i]).emit('event:new_topic', result.topicData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,77 +64,55 @@ module.exports = function(Topics) {
|
||||
};
|
||||
|
||||
Topics.getUnreadTids = function(uid, start, stop, callback) {
|
||||
var unreadTids = [],
|
||||
done = false;
|
||||
|
||||
uid = parseInt(uid, 10);
|
||||
if (uid === 0) {
|
||||
return callback(null, unreadTids);
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
if (stop === -1) {
|
||||
count = Infinity;
|
||||
} else {
|
||||
count = stop - start + 1;
|
||||
async.parallel({
|
||||
ignoredCids: function(next) {
|
||||
user.getIgnoredCategories(uid, next);
|
||||
},
|
||||
recentTids: function(next) {
|
||||
Topics.getLatestTids(0, -1, 'day', next);
|
||||
}
|
||||
|
||||
user.getIgnoredCategories(uid, function(err, ignoredCids) {
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.whilst(function() {
|
||||
return unreadTids.length < count && !done;
|
||||
}, function(next) {
|
||||
Topics.getLatestTids(start, stop, 'day', function(err, tids) {
|
||||
if (results.recentTids && !results.recentTids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
Topics.hasReadTopics(results.recentTids, uid, function(err, read) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (tids && !tids.length) {
|
||||
done = true;
|
||||
return next();
|
||||
}
|
||||
|
||||
Topics.hasReadTopics(tids, uid, function(err, read) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var newtids = tids.filter(function(tid, index) {
|
||||
var tids = results.recentTids.filter(function(tid, index) {
|
||||
return !read[index];
|
||||
});
|
||||
|
||||
privileges.topics.filter('read', newtids, uid, function(err, newtids) {
|
||||
filterTopics(uid, tids, results.ignoredCids, function(err, tids) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
filterTopicsFromIgnoredCategories(newtids, ignoredCids, function(err, newtids) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
if (stop === -1) {
|
||||
tids = tids.slice(start);
|
||||
} else {
|
||||
tids = tids.slice(start, stop + 1);
|
||||
}
|
||||
|
||||
unreadTids.push.apply(unreadTids, newtids);
|
||||
|
||||
start = stop + 1;
|
||||
stop = start + 19;
|
||||
|
||||
next();
|
||||
callback(err, tids);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, function(err) {
|
||||
callback(err, unreadTids.slice(0, count));
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
function filterTopicsFromIgnoredCategories(tids, ignoredCids, callback) {
|
||||
if (!Array.isArray(ignoredCids) || !ignoredCids.length || !tids.length) {
|
||||
function filterTopics(uid, tids, ignoredCids, callback) {
|
||||
if (!Array.isArray(ignoredCids) || !tids.length) {
|
||||
return callback(null, tids);
|
||||
}
|
||||
|
||||
@@ -146,14 +124,29 @@ module.exports = function(Topics) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var topicCids = topics.map(function(topic) {
|
||||
return topic && topic.cid.toString();
|
||||
});
|
||||
|
||||
topicCids = topicCids.filter(function(cid) {
|
||||
return ignoredCids.indexOf(cid) === -1;
|
||||
});
|
||||
|
||||
privileges.categories.filterCids('read', topicCids, uid, function(err, readableCids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
topics = topics.filter(function(topic) {
|
||||
return topic && ignoredCids.indexOf(topic.cid.toString()) === -1;
|
||||
return topic && readableCids.indexOf(topic.cid.toString()) !== -1;
|
||||
}).map(function(topic) {
|
||||
return topic.tid;
|
||||
});
|
||||
|
||||
callback(null, topics);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Topics.pushUnreadCount = function(uid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user