mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
refactor: context actor to serve an as:OrderedCollection instead of as:Page, and added context property (as per FEP-7888) to refer to it, changed audience to point to category
This commit is contained in:
@@ -326,7 +326,8 @@ Mocks.note = async (post) => {
|
|||||||
published,
|
published,
|
||||||
url: id,
|
url: id,
|
||||||
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
||||||
audience: `${nconf.get('url')}/topic/${post.topic.slug}`,
|
context: `${nconf.get('url')}/topic/${post.topic.tid}`,
|
||||||
|
audience: `${nconf.get('url')}/category/${post.category.cid}`,
|
||||||
sensitive: false, // todo
|
sensitive: false, // todo
|
||||||
summary: null,
|
summary: null,
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -62,22 +62,52 @@ Actors.note = async function (req, res) {
|
|||||||
res.status(200).json(payload);
|
res.status(200).json(payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
Actors.topic = async function (req, res) {
|
Actors.topic = async function (req, res, next) {
|
||||||
// When queried, a topic more or less returns the main pid's note representation
|
|
||||||
const allowed = await privileges.topics.can('topics:read', req.params.tid, activitypub._constants.uid);
|
const allowed = await privileges.topics.can('topics:read', req.params.tid, activitypub._constants.uid);
|
||||||
const { mainPid, slug } = await topics.getTopicFields(req.params.tid, ['mainPid', 'slug']);
|
if (!allowed) {
|
||||||
const post = (await posts.getPostSummaryByPids([mainPid], req.uid, { stripTags: false })).pop();
|
|
||||||
if (!allowed || !post) {
|
|
||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = await activitypub.mocks.note(post);
|
const page = parseInt(req.query.page, 10);
|
||||||
payload.id = `${nconf.get('url')}/topic/${req.params.tid}`;
|
const { cid, mainPid, slug, postcount } = await topics.getTopicFields(req.params.tid, ['cid', 'mainPid', 'slug', 'postcount']);
|
||||||
payload.type = 'Page';
|
const pageCount = Math.max(1, Math.ceil(postcount / meta.config.postsPerPage));
|
||||||
payload.url = `${nconf.get('url')}/topic/${slug}`;
|
let items;
|
||||||
payload.audience = `${nconf.get('url')}/category/${post.category.slug}`;
|
|
||||||
|
|
||||||
res.status(200).json(payload);
|
if (page) {
|
||||||
|
const invalidPagination = page < 1 || page > pageCount;
|
||||||
|
if (invalidPagination) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = Math.max(0, ((page - 1) * meta.config.postsPerPage) - 1);
|
||||||
|
const stop = Math.max(0, start + meta.config.postsPerPage - 1);
|
||||||
|
const pids = await posts.getPidsFromSet(`tid:${req.params.tid}:posts`, start, stop);
|
||||||
|
if (page === 1) {
|
||||||
|
pids.unshift(mainPid);
|
||||||
|
pids.length = Math.min(pids.length, meta.config.postsPerPage);
|
||||||
|
}
|
||||||
|
items = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid));
|
||||||
|
}
|
||||||
|
|
||||||
|
const object = {
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
id: `${nconf.get('url')}/topic/${req.params.tid}${page ? `?page=${page}` : ''}`,
|
||||||
|
url: `${nconf.get('url')}/topic/${slug}`,
|
||||||
|
type: items ? 'OrderedCollectionPage' : 'OrderedCollection',
|
||||||
|
audience: `${nconf.get('url')}/category/${cid}`,
|
||||||
|
totalItems: postcount,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (items) {
|
||||||
|
object.partOf = `${nconf.get('url')}/topic/${req.params.tid}`;
|
||||||
|
object.items = items;
|
||||||
|
object.next = page < pageCount ? `${nconf.get('url')}/topic/${req.params.tid}?page=${page + 1}` : null;
|
||||||
|
object.prev = page > 1 ? `${nconf.get('url')}/topic/${req.params.tid}?page=${page - 1}` : null;
|
||||||
|
}
|
||||||
|
object.first = `${nconf.get('url')}/topic/${req.params.tid}?page=1`;
|
||||||
|
object.last = `${nconf.get('url')}/topic/${req.params.tid}?page=${pageCount}`;
|
||||||
|
|
||||||
|
res.status(200).json(object);
|
||||||
};
|
};
|
||||||
|
|
||||||
Actors.category = async function (req, res, next) {
|
Actors.category = async function (req, res, next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user