Suppress sticker pack installation errors on startup re-download

This commit is contained in:
Scott Nonnenberg 2022-03-23 14:33:48 -07:00 committed by GitHub
parent 2eaacac151
commit 6a671e73f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 18 deletions

View file

@ -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; const { status, attemptedStatus } = payload;
// We do this to trigger a toast, which is still done via Backbone // 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'); trigger('pack-install-failed');
} }
@ -280,12 +287,17 @@ function clearInstalledStickerPack(): ClearInstalledStickerPackAction {
function stickerPackUpdated( function stickerPackUpdated(
packId: string, packId: string,
patch: Partial<StickerPackDBType> patch: Partial<StickerPackDBType>,
options?: { suppressError?: boolean }
): StickerPackUpdatedAction { ): StickerPackUpdatedAction {
const { status, attemptedStatus } = patch; const { status, attemptedStatus } = patch;
// We do this to trigger a toast, which is still done via Backbone // 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'); trigger('pack-install-failed');
} }

View file

@ -159,7 +159,7 @@ export function downloadQueuedPacks(): void {
const { key, status } = packsToDownload[id]; const { key, status } = packsToDownload[id];
// The queuing is done inside this function, no need to await here // 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 = {}; packsToDownload = {};
@ -503,6 +503,7 @@ export type DownloadStickerPackOptions = Readonly<{
messageId?: string; messageId?: string;
fromSync?: boolean; fromSync?: boolean;
finalStatus?: StickerPackStatusType; finalStatus?: StickerPackStatusType;
suppressError?: boolean;
}>; }>;
export async function downloadStickerPack( export async function downloadStickerPack(
@ -530,6 +531,7 @@ async function doDownloadStickerPack(
finalStatus = 'downloaded', finalStatus = 'downloaded',
messageId, messageId,
fromSync = false, fromSync = false,
suppressError = false,
}: DownloadStickerPackOptions }: DownloadStickerPackOptions
): Promise<void> { ): Promise<void> {
const { const {
@ -547,11 +549,6 @@ async function doDownloadStickerPack(
const existing = getStickerPack(packId); const existing = getStickerPack(packId);
if (!doesPackNeedDownload(existing)) { if (!doesPackNeedDownload(existing)) {
log.warn(
`Download for pack ${redactPackId(
packId
)} requested, but it does not need re-download. Skipping.`
);
return; return;
} }
@ -568,9 +565,13 @@ async function doDownloadStickerPack(
if (existing && existing.status !== 'error') { if (existing && existing.status !== 'error') {
await Data.updateStickerPackStatus(packId, 'error'); await Data.updateStickerPackStatus(packId, 'error');
stickerPackUpdated(packId, { stickerPackUpdated(
packId,
{
status: 'error', status: 'error',
}); },
{ suppressError }
);
} }
return; return;
@ -661,7 +662,7 @@ async function doDownloadStickerPack(
status: 'error' as const, status: 'error' as const,
}; };
await Data.createOrUpdateStickerPack(pack); await Data.createOrUpdateStickerPack(pack);
stickerPackAdded(pack); stickerPackAdded(pack, { suppressError });
return; return;
} }
@ -734,10 +735,14 @@ async function doDownloadStickerPack(
const errorStatus = 'error'; const errorStatus = 'error';
await Data.updateStickerPackStatus(packId, errorStatus); await Data.updateStickerPackStatus(packId, errorStatus);
if (stickerPackUpdated) { if (stickerPackUpdated) {
stickerPackUpdated(packId, { stickerPackUpdated(
packId,
{
attemptedStatus: finalStatus, attemptedStatus: finalStatus,
status: errorStatus, status: errorStatus,
}); },
{ suppressError }
);
} }
} }
} }