Stickers: Fix popup after failed load (#2498)

This commit is contained in:
Alexander Zinchuk 2023-02-08 00:38:28 +01:00
parent 49a977360c
commit d000a80d35
2 changed files with 26 additions and 22 deletions

View File

@ -163,7 +163,7 @@ export async function fetchStickers(
stickerset: 'id' in stickerSetInfo
? buildInputStickerSet(stickerSetInfo.id, stickerSetInfo.accessHash)
: buildInputStickerSetShortName(stickerSetInfo.shortName),
}));
}), undefined, true);
if (!(result instanceof GramJs.messages.StickerSet)) {
return undefined;

View File

@ -5,9 +5,11 @@ import {
} from '../../index';
import type { ActionReturnType, GlobalState, TabArgs } from '../../types';
import type { ApiStickerSetInfo } from '../../../api/types';
import type {
ApiError, ApiSticker, ApiStickerSet, ApiStickerSetInfo,
} from '../../../api/types';
import { callApi } from '../../../api/gramjs';
import { onTickEnd, pause, throttle } from '../../../util/schedulers';
import { pause, throttle } from '../../../util/schedulers';
import {
updateStickerSets,
updateStickerSet,
@ -537,27 +539,33 @@ async function loadStickers<T extends GlobalState>(
stickerSetInfo: ApiStickerSetInfo,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
const stickerSet = await callApi(
'fetchStickers',
{ stickerSetInfo },
);
global = getGlobal();
if (!stickerSet) {
onTickEnd(() => {
let stickerSet: { set: ApiStickerSet; stickers: ApiSticker[]; packs: Record<string, ApiSticker[]> } | undefined;
try {
stickerSet = await callApi(
'fetchStickers',
{ stickerSetInfo },
);
} catch (error) {
if ((error as ApiError).message === 'STICKERSET_INVALID') {
actions.showNotification({
message: translate('StickerPack.ErrorNotFound'),
tabId,
});
});
if ('shortName' in stickerSetInfo
&& selectTabState(global, tabId).openedStickerSetShortName === stickerSetInfo.shortName) {
global = updateTabState(global, {
openedStickerSetShortName: undefined,
}, tabId);
setGlobal(global);
if ('shortName' in stickerSetInfo
&& selectTabState(global, tabId).openedStickerSetShortName === stickerSetInfo.shortName) {
global = updateTabState(global, {
openedStickerSetShortName: undefined,
}, tabId);
setGlobal(global);
}
return;
}
}
global = getGlobal();
if (!stickerSet) {
// TODO handle this case when sticker cache is implemented
return;
}
@ -729,10 +737,6 @@ addActionHandler('openStickerSet', async (global, actions, payload): Promise<voi
global = getGlobal();
const set = selectStickerSet(global, stickerSetInfo);
if (!set?.shortName) {
actions.showNotification({
message: translate('StickerPack.ErrorNotFound'),
tabId,
});
return;
}