Skip to content

Node.js based forum software built for the modern web

fix: update thumbs loading logic to always include post attachments as part of thumbs (prior: was controlled by thumbsOnly flag orshowPostUploadsAsThumbnail setting)

Julian Lamc2d190e10705
diff --git a/src/topics/thumbs.js b/src/topics/thumbs.js
index 013e82a483..123f84f026 100644
--- a/src/topics/thumbs.js
+++ b/src/topics/thumbs.js
@@ -45,13 +45,22 @@ Thumbs.load = async function (topicData, options = {}) {
async function loadFromTopicData(topicData, options = {}) {
const tids = topicData.map(t => t && t.tid);
const thumbs = topicData.map(t => t && Array.isArray(t.thumbs) ? t.thumbs : []);
+ const mainPids = topicData.map(t => t.mainPid);
+
+ const mainPidAttachments = await posts.attachments.get(mainPids);
+ // Add attachments to thumb sets
+ mainPidAttachments.forEach((attachments, idx) => {
+ attachments = attachments.filter(
+ attachment => !thumbs[idx].includes(attachment.url) && (attachment.mediaType && attachment.mediaType.startsWith('image/'))
+ );
+
+ if (attachments.length) {
+ thumbs[idx].push(...attachments.map(attachment => attachment.url));
+ }
+ });
if (!options.thumbsOnly) {
- const mainPids = topicData.map(t => t.mainPid);
- const [mainPidUploads, mainPidAttachments] = await Promise.all([
- posts.uploads.list(mainPids),
- posts.attachments.get(mainPids),
- ]);
+ const mainPidUploads = await posts.uploads.list(mainPids);
// Add uploaded media to thumb sets
mainPidUploads.forEach((uploads, idx) => {
@@ -64,17 +73,6 @@ async function loadFromTopicData(topicData, options = {}) {
thumbs[idx].push(...uploads);
}
});
-
- // Add attachments to thumb sets
- mainPidAttachments.forEach((attachments, idx) => {
- attachments = attachments.filter(
- attachment => !thumbs[idx].includes(attachment.url) && (attachment.mediaType && attachment.mediaType.startsWith('image/'))
- );
-
- if (attachments.length) {
- thumbs[idx].push(...attachments.map(attachment => attachment.url));
- }
- });
}
const hasTimestampPrefix = /^\d+-/;