Add links-mode embed thumbnails, item metadata, and media filters
This commit is contained in:
@@ -37,11 +37,22 @@ function mapAttachments(message: any): CoreAttachment[] {
|
||||
}));
|
||||
}
|
||||
|
||||
/** Dimensions of the first embed part that has them: video, image, then thumbnail. */
|
||||
function embedDataSize(data: any) {
|
||||
for (const part of [data?.video, data?.image, data?.thumbnail]) {
|
||||
if (part && Number.isFinite(part.width) && Number.isFinite(part.height)) {
|
||||
return { width: part.width, height: part.height };
|
||||
}
|
||||
}
|
||||
return { width: null, height: null };
|
||||
}
|
||||
|
||||
function mapEmbeds(message: any): CoreEmbed[] {
|
||||
const assetUrl = (value: any) => value?.url ?? (typeof value === "string" ? value : null);
|
||||
|
||||
return collectionValues(message?.embeds).map((embed: any) => {
|
||||
const data = embed?.data ?? embed ?? {};
|
||||
const size = embedDataSize(data);
|
||||
return {
|
||||
type: data.type ?? null,
|
||||
url: data.url ?? null,
|
||||
@@ -49,7 +60,9 @@ function mapEmbeds(message: any): CoreEmbed[] {
|
||||
provider: data.provider?.name ?? null,
|
||||
videoUrl: assetUrl(data.video),
|
||||
imageUrl: assetUrl(data.image),
|
||||
thumbnailUrl: assetUrl(data.thumbnail)
|
||||
thumbnailUrl: assetUrl(data.thumbnail),
|
||||
width: size.width,
|
||||
height: size.height
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user