Use Promise.allSettle when fetching emojis (#6921)
This commit is contained in:
parent
411a7e22a2
commit
0c4e554534
3 changed files with 25 additions and 4 deletions
|
|
@ -87,10 +87,17 @@ const debouncedFetchEmojiByNames = debounce(async (serverUrl: string) => {
|
|||
promises.push(client.getCustomEmojiByName(name));
|
||||
}
|
||||
|
||||
const emojis = await Promise.all(promises);
|
||||
|
||||
try {
|
||||
await operator.handleCustomEmojis({emojis, prepareRecordsOnly: false});
|
||||
const emojisResult = await Promise.allSettled(promises);
|
||||
const emojis = emojisResult.reduce<CustomEmoji[]>((result, e) => {
|
||||
if (e.status === 'fulfilled') {
|
||||
result.push(e.value);
|
||||
}
|
||||
return result;
|
||||
}, []);
|
||||
if (emojis.length) {
|
||||
await operator.handleCustomEmojis({emojis, prepareRecordsOnly: false});
|
||||
}
|
||||
return {error: undefined};
|
||||
} catch (error) {
|
||||
return {error};
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ const Emoji = (props: EmojiProps) => {
|
|||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
} else if (name && !isUnicodeEmoji(name)) {
|
||||
} else if (name && (name.length > 1 || !isUnicodeEmoji(name))) {
|
||||
fetchCustomEmojiInBatch(serverUrl, name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,20 @@ import {registerNavigationListeners} from '@screens/navigation';
|
|||
let alreadyInitialized = false;
|
||||
let serverCredentials: ServerCredential[];
|
||||
|
||||
// Fallback Polyfill for Promise.allSettle
|
||||
Promise.allSettled = Promise.allSettled || (<T>(promises: Array<Promise<T>>) => Promise.all(
|
||||
promises.map((p) => p.
|
||||
then((value) => ({
|
||||
status: 'fulfilled',
|
||||
value,
|
||||
})).
|
||||
catch((reason) => ({
|
||||
status: 'rejected',
|
||||
reason,
|
||||
})),
|
||||
),
|
||||
));
|
||||
|
||||
export async function initialize() {
|
||||
if (!alreadyInitialized) {
|
||||
alreadyInitialized = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue