mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-20 03:11:57 +01:00
fix: update thumbs loading logic to always include post attachments as part of thumbs (prior: was controlled by thumbsOnly flag orshowPostUploadsAsThumbnail setting)
This commit is contained in:
@@ -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+-/;
|
||||
|
||||
Reference in New Issue
Block a user