Skip to content

Node.js based forum software built for the modern web

Add basic author information to topic data (#12202)

Opliko2d8026ebb75c
diff --git a/public/openapi/read/topic/topic_id.yaml b/public/openapi/read/topic/topic_id.yaml
index cee628cce2..8b6ffdbd90 100644
--- a/public/openapi/read/topic/topic_id.yaml
+++ b/public/openapi/read/topic/topic_id.yaml
@@ -408,6 +408,20 @@ get:
type: string
postIndex:
type: number
+ author:
+ type: object
+ required: [username, uid]
+ properties:
+ username:
+ type: string
+ userslug:
+ type: string
+ uid:
+ type: number
+ fullname:
+ type: string
+ displayname:
+ type: string
- type: object
description: Optional properties that may or may not be present (except for `tid`, which is always present, and is only here as a hack to pass validation)
properties:
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 518882d826..16e1cad3a7 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -114,7 +114,8 @@ topicsController.get = async function getTopic(req, res, next) {
topicData.postIndex = postIndex;
- await Promise.all([
+ const [author] = await Promise.all([
+ user.getUserFields(topicData.uid, ['username', 'userslug']),
buildBreadcrumbs(topicData),
addOldCategory(topicData, userPrivileges),
addTags(topicData, req, res, currentPage),
@@ -123,12 +124,12 @@ topicsController.get = async function getTopic(req, res, next) {
analytics.increment([`pageviews:byCid:${topicData.category.cid}`]),
]);
+ topicData.author = author;
topicData.pagination = pagination.create(currentPage, pageCount, req.query);
topicData.pagination.rel.forEach((rel) => {
rel.href = `${url}/topic/${topicData.slug}${rel.href}`;
res.locals.linkTags.push(rel);
});
-
res.render('topic', topicData);
};