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;
// 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<StickerPackDBType>
patch: Partial<StickerPackDBType>,
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');
}

View File

@ -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<void> {
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 }
);
}
}
}