From 6a671e73f9eaf93184492f75c1ba5ca61b0fcb9f Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 23 Mar 2022 14:33:48 -0700 Subject: [PATCH] Suppress sticker pack installation errors on startup re-download --- ts/state/ducks/stickers.ts | 20 ++++++++++++++++---- ts/types/Stickers.ts | 33 +++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/ts/state/ducks/stickers.ts b/ts/state/ducks/stickers.ts index d79febed9..ab06e75e3 100644 --- a/ts/state/ducks/stickers.ts +++ b/ts/state/ducks/stickers.ts @@ -164,11 +164,18 @@ function stickerAdded(payload: StickerDBType): StickerAddedAction { }; } -function stickerPackAdded(payload: StickerPackDBType): StickerPackAddedAction { +function stickerPackAdded( + payload: StickerPackDBType, + options?: { suppressError?: boolean } +): StickerPackAddedAction { const { status, attemptedStatus } = payload; // We do this to trigger a toast, which is still done via Backbone - if (status === 'error' && attemptedStatus === 'installed') { + if ( + status === 'error' && + attemptedStatus === 'installed' && + !options?.suppressError + ) { trigger('pack-install-failed'); } @@ -280,12 +287,17 @@ function clearInstalledStickerPack(): ClearInstalledStickerPackAction { function stickerPackUpdated( packId: string, - patch: Partial + patch: Partial, + options?: { suppressError?: boolean } ): StickerPackUpdatedAction { const { status, attemptedStatus } = patch; // We do this to trigger a toast, which is still done via Backbone - if (status === 'error' && attemptedStatus === 'installed') { + if ( + status === 'error' && + attemptedStatus === 'installed' && + !options?.suppressError + ) { trigger('pack-install-failed'); } diff --git a/ts/types/Stickers.ts b/ts/types/Stickers.ts index 39dcf296f..76131751f 100644 --- a/ts/types/Stickers.ts +++ b/ts/types/Stickers.ts @@ -159,7 +159,7 @@ export function downloadQueuedPacks(): void { const { key, status } = packsToDownload[id]; // The queuing is done inside this function, no need to await here - downloadStickerPack(id, key, { finalStatus: status }); + downloadStickerPack(id, key, { finalStatus: status, suppressError: true }); } packsToDownload = {}; @@ -503,6 +503,7 @@ export type DownloadStickerPackOptions = Readonly<{ messageId?: string; fromSync?: boolean; finalStatus?: StickerPackStatusType; + suppressError?: boolean; }>; export async function downloadStickerPack( @@ -530,6 +531,7 @@ async function doDownloadStickerPack( finalStatus = 'downloaded', messageId, fromSync = false, + suppressError = false, }: DownloadStickerPackOptions ): Promise { const { @@ -547,11 +549,6 @@ async function doDownloadStickerPack( const existing = getStickerPack(packId); if (!doesPackNeedDownload(existing)) { - log.warn( - `Download for pack ${redactPackId( - packId - )} requested, but it does not need re-download. Skipping.` - ); return; } @@ -568,9 +565,13 @@ async function doDownloadStickerPack( if (existing && existing.status !== 'error') { await Data.updateStickerPackStatus(packId, 'error'); - stickerPackUpdated(packId, { - status: 'error', - }); + stickerPackUpdated( + packId, + { + status: 'error', + }, + { suppressError } + ); } return; @@ -661,7 +662,7 @@ async function doDownloadStickerPack( status: 'error' as const, }; await Data.createOrUpdateStickerPack(pack); - stickerPackAdded(pack); + stickerPackAdded(pack, { suppressError }); return; } @@ -734,10 +735,14 @@ async function doDownloadStickerPack( const errorStatus = 'error'; await Data.updateStickerPackStatus(packId, errorStatus); if (stickerPackUpdated) { - stickerPackUpdated(packId, { - attemptedStatus: finalStatus, - status: errorStatus, - }); + stickerPackUpdated( + packId, + { + attemptedStatus: finalStatus, + status: errorStatus, + }, + { suppressError } + ); } } }