From e13a2feec88f16695363a681b21766132c5ecdc8 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 28 Dec 2023 11:58:50 +0800 Subject: [PATCH] Prioritise local instance unfurl over remote --- src/components/status.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index d9402b83..6102a651 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -2364,9 +2364,18 @@ function _unfurlMastodonLink(instance, url) { } if (remoteInstanceFetch) { - return Promise.any([remoteInstanceFetch, mastoSearchFetch]) - .then(handleFulfill) - .catch(handleCatch); + // return Promise.any([remoteInstanceFetch, mastoSearchFetch]) + // .then(handleFulfill) + // .catch(handleCatch); + // If mastoSearchFetch is fulfilled within 3s, return it, else return remoteInstanceFetch + const finalPromise = Promise.race([ + mastoSearchFetch, + new Promise((resolve, reject) => setTimeout(reject, 3000)), + ]).catch(() => { + // If remoteInstanceFetch is fullfilled, return it, else return mastoSearchFetch + return remoteInstanceFetch.catch(() => mastoSearchFetch); + }); + return finalPromise.then(handleFulfill).catch(handleCatch); } else { return mastoSearchFetch.then(handleFulfill).catch(handleCatch); }