mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: paginate recentposts.rss and
category/1/recentposts.rss
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const winston = require('winston');
|
||||
const _ = require('lodash');
|
||||
|
||||
const db = require('../database');
|
||||
@@ -11,11 +12,14 @@ const plugins = require('../plugins');
|
||||
const batch = require('../batch');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
Categories.getRecentReplies = async function (cid, uid, count) {
|
||||
if (!parseInt(count, 10)) {
|
||||
return [];
|
||||
Categories.getRecentReplies = async function (cid, uid, start, stop) {
|
||||
// backwards compatibility, treat start as count
|
||||
if (stop === undefined && start > 0) {
|
||||
winston.warn('[Categories.getRecentReplies] 3 params deprecated please use Categories.getRecentReplies(cid, uid, start, stop)');
|
||||
stop = start - 1;
|
||||
start = 0;
|
||||
}
|
||||
let pids = await db.getSortedSetRevRange(`cid:${cid}:pids`, 0, count - 1);
|
||||
let pids = await db.getSortedSetRevRange(`cid:${cid}:pids`, start, stop);
|
||||
pids = await privileges.posts.filter('topics:read', pids, uid);
|
||||
return await posts.getPostSummaryByPids(pids, uid, { stripTags: true });
|
||||
};
|
||||
|
||||
@@ -307,7 +307,11 @@ async function generateForRecentPosts(req, res, next) {
|
||||
if (meta.config['feeds:disableRSS']) {
|
||||
return next();
|
||||
}
|
||||
const postData = await posts.getRecentPosts(req.uid, 0, 19, 'month');
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
const postsPerPage = 20;
|
||||
const start = Math.max(0, (page - 1) * postsPerPage);
|
||||
const stop = start + postsPerPage - 1;
|
||||
const postData = await posts.getRecentPosts(req.uid, start, stop, 'month');
|
||||
const feed = generateForPostsFeed({
|
||||
title: 'Recent Posts',
|
||||
description: 'A list of recent posts',
|
||||
@@ -323,11 +327,14 @@ async function generateForCategoryRecentPosts(req, res) {
|
||||
return controllers404.handle404(req, res);
|
||||
}
|
||||
const cid = req.params.category_id;
|
||||
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
const topicsPerPage = 20;
|
||||
const start = Math.max(0, (page - 1) * topicsPerPage);
|
||||
const stop = start + topicsPerPage - 1;
|
||||
const [userPrivileges, category, postData] = await Promise.all([
|
||||
privileges.categories.get(cid, req.uid),
|
||||
categories.getCategoryData(cid),
|
||||
categories.getRecentReplies(cid, req.uid || req.query.uid || 0, 20),
|
||||
categories.getRecentReplies(cid, req.uid || req.query.uid || 0, start, stop),
|
||||
]);
|
||||
|
||||
if (!category) {
|
||||
|
||||
@@ -10,7 +10,7 @@ const SocketCategories = module.exports;
|
||||
require('./categories/search')(SocketCategories);
|
||||
|
||||
SocketCategories.getRecentReplies = async function (socket, cid) {
|
||||
return await categories.getRecentReplies(cid, socket.uid, 4);
|
||||
return await categories.getRecentReplies(cid, socket.uid, 0, 4);
|
||||
};
|
||||
|
||||
SocketCategories.get = async function (socket) {
|
||||
|
||||
Reference in New Issue
Block a user