Node.js based forum software built for the modern web
feat: add post attachments to topic thumbnails
Julian Lam2aeabce56696
diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.jsindex d8ea8dd00e..69c682d2cb 100644--- a/src/controllers/activitypub/topics.js+++ b/src/controllers/activitypub/topics.js@@ -67,6 +67,7 @@ controller.list = async function (req, res) {tag: req.query.tag,targetUid: targetUid,});+data.name = '[[activitypub:world.name]]';delete data.children;diff --git a/src/topics/thumbs.js b/src/topics/thumbs.jsindex f6dcdd2187..4e770a043a 100644--- a/src/topics/thumbs.js+++ b/src/topics/thumbs.js@@ -13,6 +13,7 @@ const posts = require('../posts');const meta = require('../meta');const cache = require('../cache');+const topics = module.parent.exports;const Thumbs = module.exports;Thumbs.exists = async function (id, path) {@@ -23,7 +24,12 @@ Thumbs.exists = async function (id, path) {};Thumbs.load = async function (topicData) {- const topicsWithThumbs = topicData.filter(t => t && parseInt(t.numThumbs, 10) > 0);+ const mainPids = topicData.map(t => t.mainPid);+ let hashes = await posts.getPostsFields(mainPids, ['attachments']);+ hashes = hashes.map(o => o.attachments);+ const topicsWithThumbs = topicData.filter((t, idx) => t &&+ (parseInt(t.numThumbs, 10) > 0 ||+ (hashes[idx] && hashes[idx].length)));const tidsWithThumbs = topicsWithThumbs.map(t => t.tid);const thumbs = await Thumbs.get(tidsWithThumbs);const tidToThumbs = _.zipObject(tidsWithThumbs, thumbs);@@ -44,8 +50,23 @@ Thumbs.get = async function (tids) {const hasTimestampPrefix = /^\d+-/;const upload_url = nconf.get('relative_path') + nconf.get('upload_url');+ const exists = await topics.exists(tids);const sets = tids.map(tid => `${validator.isUUID(String(tid)) ? 'draft' : 'topic'}:${tid}:thumbs`);const thumbs = await Promise.all(sets.map(getThumbs));++ // Add attachments to thumb sets+ await Promise.all(tids.map(async (tid, idx) => {+ if (exists[idx]) {+ const mainPid = await topics.getTopicField(tid, 'mainPid');+ let attachments = await posts.attachments.get(mainPid);+ attachments = attachments.filter(attachment => attachment.mediaType.startsWith('image/'));++ if (attachments.length) {+ thumbs[idx].push(...attachments.map(attachment => attachment.url));+ }+ }+ }));+let response = thumbs.map((thumbSet, idx) => thumbSet.map(thumb => ({id: tids[idx],name: (() => {