mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-08 11:43:16 +02:00
added getRecentPost
This commit is contained in:
35
src/posts.js
35
src/posts.js
@@ -197,6 +197,35 @@ var db = require('./database'),
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getRecentPosts = function(uid, start, stop, term, callback) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000
|
||||
};
|
||||
|
||||
var since = terms.day;
|
||||
if (terms[term]) {
|
||||
since = terms[term];
|
||||
}
|
||||
|
||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||
|
||||
db.getSortedSetRevRangeByScore(['posts:pid', '+inf', Date.now() - since, 'LIMIT', start, count], function(err, pids) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.filter(pids, function(pid, next) {
|
||||
postTools.privileges(pid, uid, function(err, privileges) {
|
||||
next(!err && privileges.read);
|
||||
});
|
||||
}, function(pids) {
|
||||
Posts.getPostSummaryByPids(pids, true, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Posts.addUserInfoToPost = function(post, callback) {
|
||||
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
|
||||
if (err) {
|
||||
@@ -262,10 +291,10 @@ var db = require('./database'),
|
||||
|
||||
if (parseInt(postData.deleted, 10) === 1) {
|
||||
return callback(null);
|
||||
} else {
|
||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||
next(null, postData);
|
||||
}
|
||||
|
||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||
next(null, postData);
|
||||
});
|
||||
},
|
||||
function(postData, next) {
|
||||
|
||||
Reference in New Issue
Block a user