mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 05:37:35 +02: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 = {}) {
|
async function loadFromTopicData(topicData, options = {}) {
|
||||||
const tids = topicData.map(t => t && t.tid);
|
const tids = topicData.map(t => t && t.tid);
|
||||||
const thumbs = topicData.map(t => t && Array.isArray(t.thumbs) ? t.thumbs : []);
|
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) {
|
if (!options.thumbsOnly) {
|
||||||
const mainPids = topicData.map(t => t.mainPid);
|
const mainPidUploads = await posts.uploads.list(mainPids);
|
||||||
const [mainPidUploads, mainPidAttachments] = await Promise.all([
|
|
||||||
posts.uploads.list(mainPids),
|
|
||||||
posts.attachments.get(mainPids),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Add uploaded media to thumb sets
|
// Add uploaded media to thumb sets
|
||||||
mainPidUploads.forEach((uploads, idx) => {
|
mainPidUploads.forEach((uploads, idx) => {
|
||||||
@@ -64,17 +73,6 @@ async function loadFromTopicData(topicData, options = {}) {
|
|||||||
thumbs[idx].push(...uploads);
|
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+-/;
|
const hasTimestampPrefix = /^\d+-/;
|
||||||
|
|||||||
Reference in New Issue
Block a user