2014-09-03 15:16:41 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-02-10 15:26:17 +03:00
|
|
|
var async = require('async');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
var privileges = require('../privileges');
|
2014-09-03 15:16:41 -04:00
|
|
|
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
module.exports = function (Posts) {
|
2014-09-03 15:16:41 -04:00
|
|
|
var terms = {
|
|
|
|
|
day: 86400000,
|
|
|
|
|
week: 604800000,
|
|
|
|
|
month: 2592000000
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
Posts.getRecentPosts = function (uid, start, stop, term, callback) {
|
2015-03-14 20:46:28 -04:00
|
|
|
var min = 0;
|
2014-09-03 15:16:41 -04:00
|
|
|
if (terms[term]) {
|
2015-03-14 20:46:28 -04:00
|
|
|
min = Date.now() - terms[term];
|
2014-09-03 15:16:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
|
|
|
|
|
2014-11-09 01:30:27 -05:00
|
|
|
async.waterfall([
|
2016-10-13 11:43:39 +02:00
|
|
|
function (next) {
|
2015-03-14 20:46:28 -04:00
|
|
|
db.getSortedSetRevRangeByScore('posts:pid', start, count, '+inf', min, next);
|
2014-11-09 01:30:27 -05:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (pids, next) {
|
2014-11-09 01:30:27 -05:00
|
|
|
privileges.posts.filter('read', pids, uid, next);
|
|
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (pids, next) {
|
2014-11-09 01:30:27 -05:00
|
|
|
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
2014-09-03 15:16:41 -04:00
|
|
|
}
|
2014-11-09 01:30:27 -05:00
|
|
|
], callback);
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
Posts.getRecentPosterUids = function (start, stop, callback) {
|
2014-11-09 01:30:27 -05:00
|
|
|
async.waterfall([
|
2016-10-13 11:43:39 +02:00
|
|
|
function (next) {
|
2015-03-31 23:40:58 -04:00
|
|
|
db.getSortedSetRevRange('posts:pid', start, stop, next);
|
2014-11-09 01:30:27 -05:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (pids, next) {
|
2014-11-09 01:30:27 -05:00
|
|
|
Posts.getPostsFields(pids, ['uid'], next);
|
|
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (postData, next) {
|
2017-02-10 15:26:17 +03:00
|
|
|
var uids = postData.map(function (post) {
|
2014-09-03 15:16:41 -04:00
|
|
|
return post && post.uid;
|
2017-02-10 15:26:17 +03:00
|
|
|
}).filter(function (uid, index, array) {
|
|
|
|
|
return uid && array.indexOf(uid) === index;
|
2014-09-03 15:16:41 -04:00
|
|
|
});
|
2017-02-10 15:26:17 +03:00
|
|
|
next(null, uids);
|
2014-11-09 01:30:27 -05:00
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|