diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index d3a56866e8..00cf8d1cc3 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -288,6 +288,7 @@ Mocks.category = async (actors) => { bgColor, backgroundImage, imageClass: 'cover', + numRecentReplies: 1, // followerCount, // followingCount, diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index cb7056bfbb..c162d438b8 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -10,6 +10,7 @@ const topics = require('../topics'); const privileges = require('../privileges'); const plugins = require('../plugins'); const batch = require('../batch'); +const utils = require('../utils'); module.exports = function (Categories) { Categories.getRecentReplies = async function (cid, uid, start, stop) { @@ -27,7 +28,7 @@ module.exports = function (Categories) { Categories.updateRecentTid = async function (cid, tid) { const [count, numRecentReplies] = await Promise.all([ db.sortedSetCard(`cid:${cid}:recent_tids`), - db.getObjectField(`category:${cid}`, 'numRecentReplies'), + db.getObjectField(`${utils.isNumber(cid) ? 'category' : 'categoryRemote'}:${cid}`, 'numRecentReplies'), ]); if (count >= numRecentReplies) { @@ -131,7 +132,10 @@ module.exports = function (Categories) { function assignTopicsToCategories(categories, topics) { categories.forEach((category) => { if (category) { - category.posts = topics.filter(t => t.cid && (t.cid === category.cid || t.parentCids.includes(category.cid))) + category.posts = topics.filter( + t => t.cid && + (t.cid === category.cid || (t.parentCids && t.parentCids.includes(category.cid))) + ) .sort((a, b) => b.timestamp - a.timestamp) .slice(0, parseInt(category.numRecentReplies, 10)); } diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.js index b2d1c25e7f..b7d6da0095 100644 --- a/src/controllers/activitypub/topics.js +++ b/src/controllers/activitypub/topics.js @@ -68,6 +68,12 @@ controller.list = async function (req, res) { categories.getRecentTopicReplies(categoryData, req.uid, req.query), categories.setUnread(data.categories, cids, req.uid), ]); + data.categories.forEach((category) => { + if (category) { + helpers.trimChildren(category); + helpers.setCategoryTeaser(category); + } + }); data.title = translator.escape(data.name); data.privileges = userPrivileges;