Filter out invalid previews

The call to cli.getUrlPreview() might return an empty object ({}), which means
there is in fact no preview for that URL.

Signed-off-by: Paulo Pinto <paulo.pinto@automattic.com>
This commit is contained in:
Paulo Pinto 2021-09-27 18:03:15 +01:00
parent dabc13c98f
commit 432dd994bd

View file

@ -87,7 +87,10 @@ const fetchPreviews = (cli: MatrixClient, links: string[], ts: number):
Promise<[string, IPreviewUrlResponse][]> => {
return Promise.all<[string, IPreviewUrlResponse] | void>(links.map(async link => {
try {
return [link, await cli.getUrlPreview(link, ts)];
const preview = await cli.getUrlPreview(link, ts);
if (preview && Object.keys(preview).length > 0) {
return [link, preview];
}
} catch (error) {
console.error("Failed to get URL preview: " + error);
}