Don't refetch failed unfurls

This commit is contained in:
Lim Chee Aun 2023-02-23 22:53:28 +08:00
parent e2a679e202
commit 7ebd0e7601

View file

@ -1180,11 +1180,15 @@ function isMastodonLinkMaybe(url) {
}
const denylistDomains = /(twitter|github)\.com/i;
const failedUnfurls = {};
function _unfurlMastodonLink(instance, url) {
if (denylistDomains.test(url)) {
return;
}
if (failedUnfurls[url]) {
return;
}
const instanceRegex = new RegExp(instance + '/');
if (instanceRegex.test(states.unfurledLinks[url]?.url)) {
return Promise.resolve(states.unfurledLinks[url]);
@ -1211,10 +1215,12 @@ function _unfurlMastodonLink(instance, url) {
states.unfurledLinks[url] = result;
return result;
} else {
failedUnfurls[url] = true;
throw new Error('No results');
}
})
.catch((e) => {
failedUnfurls[url] = true;
console.warn(e);
// Silently fail
});