2014-09-03 15:16:41 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-07-17 19:05:55 -04:00
|
|
|
const _ = require('lodash');
|
2018-10-20 14:40:48 -04:00
|
|
|
|
2019-07-17 19:05:55 -04:00
|
|
|
const db = require('../database');
|
|
|
|
|
const privileges = require('../privileges');
|
2014-09-03 15:16:41 -04:00
|
|
|
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
module.exports = function (Posts) {
|
2019-07-17 19:05:55 -04:00
|
|
|
const terms = {
|
2014-09-03 15:16:41 -04:00
|
|
|
day: 86400000,
|
|
|
|
|
week: 604800000,
|
2017-02-17 19:31:21 -07:00
|
|
|
month: 2592000000,
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|
|
|
|
|
|
2019-07-17 19:05:55 -04:00
|
|
|
Posts.getRecentPosts = async function (uid, start, stop, term) {
|
|
|
|
|
let 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
|
|
|
}
|
|
|
|
|
|
2019-07-17 19:05:55 -04:00
|
|
|
const count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
|
|
|
|
let pids = await db.getSortedSetRevRangeByScore('posts:pid', start, count, '+inf', min);
|
|
|
|
|
pids = await privileges.posts.filter('topics:read', pids, uid);
|
|
|
|
|
return await Posts.getPostSummaryByPids(pids, uid, { stripTags: true });
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|
|
|
|
|
|
2019-07-17 19:05:55 -04:00
|
|
|
Posts.getRecentPosterUids = async function (start, stop) {
|
|
|
|
|
const pids = await db.getSortedSetRevRange('posts:pid', start, stop);
|
|
|
|
|
const postData = await Posts.getPostsFields(pids, ['uid']);
|
|
|
|
|
return _.uniq(postData.map(p => p && p.uid).filter(uid => parseInt(uid, 10)));
|
2017-02-18 14:42:15 -07:00
|
|
|
};
|
2014-09-03 15:16:41 -04:00
|
|
|
};
|