mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: send back empty array if no direct replies, bug with reply generation
This commit is contained in:
@@ -5,6 +5,7 @@ const mime = require('mime');
|
||||
const path = require('path');
|
||||
const sanitize = require('sanitize-html');
|
||||
|
||||
const db = require('../database');
|
||||
const meta = require('../meta');
|
||||
const user = require('../user');
|
||||
const categories = require('../categories');
|
||||
@@ -384,6 +385,8 @@ Mocks.note = async (post) => {
|
||||
return payload;
|
||||
});
|
||||
|
||||
const replyCount = await db.sortedSetCard(`pid:${post.pid}:replies`);
|
||||
|
||||
const object = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id,
|
||||
@@ -403,7 +406,7 @@ Mocks.note = async (post) => {
|
||||
source,
|
||||
tag,
|
||||
attachment,
|
||||
replies: `${id}/replies`,
|
||||
replies: replyCount > 0 ? `${id}/replies` : [],
|
||||
};
|
||||
|
||||
return object;
|
||||
|
||||
@@ -63,6 +63,12 @@ Actors.note = async function (req, res) {
|
||||
};
|
||||
|
||||
Actors.replies = async function (req, res) {
|
||||
const allowed = utils.isNumber(req.params.pid) && await privileges.posts.can('topics:read', req.params.pid, activitypub._constants.uid);
|
||||
const exists = await posts.exists(req.params.pid);
|
||||
if (!allowed || !exists) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
const page = parseInt(req.query.page, 10);
|
||||
const replies = await activitypub.helpers.generateCollection({
|
||||
set: `pid:${req.params.pid}:replies`,
|
||||
@@ -71,6 +77,9 @@ Actors.replies = async function (req, res) {
|
||||
url: `${nconf.get('url')}/post/${req.params.pid}/replies`,
|
||||
});
|
||||
|
||||
// Convert pids to urls
|
||||
replies.orderedItems = replies.orderedItems.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
||||
|
||||
const object = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: `${nconf.get('url')}/post/${req.params.pid}/replies${replies.orderedItems && page ? `?page=${page}` : ''}`,
|
||||
@@ -78,9 +87,6 @@ Actors.replies = async function (req, res) {
|
||||
...replies,
|
||||
}
|
||||
|
||||
// Convert pids to urls
|
||||
replies.orderedItems = replies.orderedItems.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
||||
|
||||
res.status(200).json(object);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user