2014-09-03 15:16:41 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-02-10 15:26:17 +03:00
|
|
|
var async = require('async');
|
2018-10-20 14:40:48 -04:00
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
2017-02-10 15:26:17 +03:00
|
|
|
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,
|
2017-02-17 19:31:21 -07:00
|
|
|
month: 2592000000,
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|
|
|
|
|
|
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) {
|
2019-03-16 14:51:46 -04:00
|
|
|
privileges.posts.filter('topics:read', pids, uid, next);
|
2014-11-09 01:30:27 -05:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (pids, next) {
|
2017-02-18 12:30:49 -07:00
|
|
|
Posts.getPostSummaryByPids(pids, uid, { stripTags: true }, next);
|
2017-02-17 19:31:21 -07: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) {
|
2018-10-20 14:40:48 -04:00
|
|
|
var uids = _.uniq(postData.map(post => post && post.uid).filter(uid => parseInt(uid, 10)));
|
|
|
|
|
|
2017-02-10 15:26:17 +03:00
|
|
|
next(null, uids);
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2014-11-09 01:30:27 -05:00
|
|
|
], callback);
|
2017-02-18 14:42:15 -07:00
|
|
|
};
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|