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.noop = function() {};
|
||||||
|
|
||||||
helpers.KEY_LIMIT = 100;
|
helpers.KEY_LIMIT = 300;
|
||||||
|
|
||||||
module.exports = helpers;
|
module.exports = helpers;
|
||||||
@@ -196,15 +196,17 @@
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
groupNames = internals.removeEphemeralGroups(groupNames);
|
|
||||||
if (groupNames.length === 0) {
|
|
||||||
return callback(null, null);
|
|
||||||
}
|
|
||||||
var results = [];
|
var results = [];
|
||||||
uids.forEach(function() {
|
uids.forEach(function() {
|
||||||
results.push(false);
|
results.push(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
groupNames = internals.removeEphemeralGroups(groupNames);
|
||||||
|
if (groupNames.length === 0) {
|
||||||
|
return callback(null, results);
|
||||||
|
}
|
||||||
|
|
||||||
async.each(groupNames, function(groupName, next) {
|
async.each(groupNames, function(groupName, next) {
|
||||||
Groups.isMembers(uids, groupName, function(err, isMembers) {
|
Groups.isMembers(uids, groupName, function(err, isMembers) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -46,9 +46,10 @@ SocketTopics.post = function(socket, data, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i=0; i<uids.length; ++i) {
|
for(var i=0; i<uids.length; ++i) {
|
||||||
if (parseInt(uids[i], 10) !== socket.uid) {
|
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);
|
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) {
|
Topics.getUnreadTids = function(uid, start, stop, callback) {
|
||||||
var unreadTids = [],
|
|
||||||
done = false;
|
|
||||||
|
|
||||||
uid = parseInt(uid, 10);
|
uid = parseInt(uid, 10);
|
||||||
if (uid === 0) {
|
if (uid === 0) {
|
||||||
return callback(null, unreadTids);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = 0;
|
async.parallel({
|
||||||
if (stop === -1) {
|
ignoredCids: function(next) {
|
||||||
count = Infinity;
|
user.getIgnoredCategories(uid, next);
|
||||||
} else {
|
},
|
||||||
count = stop - start + 1;
|
recentTids: function(next) {
|
||||||
}
|
Topics.getLatestTids(0, -1, 'day', next);
|
||||||
|
}
|
||||||
user.getIgnoredCategories(uid, function(err, ignoredCids) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.whilst(function() {
|
if (results.recentTids && !results.recentTids.length) {
|
||||||
return unreadTids.length < count && !done;
|
return callback(null, []);
|
||||||
}, function(next) {
|
}
|
||||||
Topics.getLatestTids(start, stop, 'day', function(err, tids) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tids && !tids.length) {
|
Topics.hasReadTopics(results.recentTids, uid, function(err, read) {
|
||||||
done = true;
|
if (err) {
|
||||||
return next();
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.hasReadTopics(tids, uid, function(err, read) {
|
var tids = results.recentTids.filter(function(tid, index) {
|
||||||
if (err) {
|
return !read[index];
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
var newtids = tids.filter(function(tid, index) {
|
|
||||||
return !read[index];
|
|
||||||
});
|
|
||||||
|
|
||||||
privileges.topics.filter('read', newtids, uid, function(err, newtids) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
filterTopicsFromIgnoredCategories(newtids, ignoredCids, function(err, newtids) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
unreadTids.push.apply(unreadTids, newtids);
|
|
||||||
|
|
||||||
start = stop + 1;
|
|
||||||
stop = start + 19;
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}, function(err) {
|
|
||||||
callback(err, unreadTids.slice(0, count));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
filterTopics(uid, tids, results.ignoredCids, function(err, tids) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stop === -1) {
|
||||||
|
tids = tids.slice(start);
|
||||||
|
} else {
|
||||||
|
tids = tids.slice(start, stop + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(err, tids);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function filterTopicsFromIgnoredCategories(tids, ignoredCids, callback) {
|
function filterTopics(uid, tids, ignoredCids, callback) {
|
||||||
if (!Array.isArray(ignoredCids) || !ignoredCids.length || !tids.length) {
|
if (!Array.isArray(ignoredCids) || !tids.length) {
|
||||||
return callback(null, tids);
|
return callback(null, tids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,13 +124,28 @@ module.exports = function(Topics) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
topics = topics.filter(function(topic) {
|
|
||||||
return topic && ignoredCids.indexOf(topic.cid.toString()) === -1;
|
var topicCids = topics.map(function(topic) {
|
||||||
}).map(function(topic) {
|
return topic && topic.cid.toString();
|
||||||
return topic.tid;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(null, topics);
|
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 && readableCids.indexOf(topic.cid.toString()) !== -1;
|
||||||
|
}).map(function(topic) {
|
||||||
|
return topic.tid;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, topics);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user