Sticker Tooltip: Fix missing added sticker sets (#1617)
This commit is contained in:
parent
bf395194a9
commit
846b47cb32
@ -1,5 +1,5 @@
|
|||||||
import React, {
|
import React, {
|
||||||
FC, useCallback, memo, useEffect, useRef, useState,
|
FC, useCallback, memo, useRef, useState,
|
||||||
} from '../../../lib/teact/teact';
|
} from '../../../lib/teact/teact';
|
||||||
import { getDispatch, withGlobal } from '../../../lib/teact/teactn';
|
import { getDispatch, withGlobal } from '../../../lib/teact/teactn';
|
||||||
|
|
||||||
@ -69,8 +69,6 @@ const SettingsGeneral: FC<OwnProps & StateProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
setSettingOption,
|
setSettingOption,
|
||||||
loadStickerSets,
|
|
||||||
loadAddedStickers,
|
|
||||||
} = getDispatch();
|
} = getDispatch();
|
||||||
|
|
||||||
// eslint-disable-next-line no-null/no-null
|
// eslint-disable-next-line no-null/no-null
|
||||||
@ -90,16 +88,6 @@ const SettingsGeneral: FC<OwnProps & StateProps> = ({
|
|||||||
},
|
},
|
||||||
] : undefined;
|
] : undefined;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadStickerSets();
|
|
||||||
}, [loadStickerSets]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (stickerSetIds?.length) {
|
|
||||||
loadAddedStickers();
|
|
||||||
}
|
|
||||||
}, [stickerSetIds, loadAddedStickers]);
|
|
||||||
|
|
||||||
const handleAnimationLevelChange = useCallback((newLevel: number) => {
|
const handleAnimationLevelChange = useCallback((newLevel: number) => {
|
||||||
ANIMATION_LEVEL_OPTIONS.forEach((_, i) => {
|
ANIMATION_LEVEL_OPTIONS.forEach((_, i) => {
|
||||||
document.body.classList.toggle(`animation-level-${i}`, newLevel === i);
|
document.body.classList.toggle(`animation-level-${i}`, newLevel === i);
|
||||||
|
|||||||
@ -69,6 +69,7 @@ type StateProps = {
|
|||||||
language?: LangCode;
|
language?: LangCode;
|
||||||
wasTimeFormatSetManually?: boolean;
|
wasTimeFormatSetManually?: boolean;
|
||||||
isCallFallbackConfirmOpen: boolean;
|
isCallFallbackConfirmOpen: boolean;
|
||||||
|
addedSetIds?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const NOTIFICATION_INTERVAL = 1000;
|
const NOTIFICATION_INTERVAL = 1000;
|
||||||
@ -97,6 +98,7 @@ const Main: FC<StateProps> = ({
|
|||||||
language,
|
language,
|
||||||
wasTimeFormatSetManually,
|
wasTimeFormatSetManually,
|
||||||
isCallFallbackConfirmOpen,
|
isCallFallbackConfirmOpen,
|
||||||
|
addedSetIds,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
loadAnimatedEmojis,
|
loadAnimatedEmojis,
|
||||||
@ -106,10 +108,14 @@ const Main: FC<StateProps> = ({
|
|||||||
loadTopInlineBots,
|
loadTopInlineBots,
|
||||||
loadEmojiKeywords,
|
loadEmojiKeywords,
|
||||||
loadCountryList,
|
loadCountryList,
|
||||||
|
loadStickerSets,
|
||||||
|
loadAddedStickers,
|
||||||
|
loadFavoriteStickers,
|
||||||
ensureTimeFormat,
|
ensureTimeFormat,
|
||||||
openStickerSetShortName,
|
openStickerSetShortName,
|
||||||
checkVersionNotification,
|
checkVersionNotification,
|
||||||
} = getDispatch();
|
} = getDispatch();
|
||||||
|
const isSynced = Boolean(lastSyncTime);
|
||||||
|
|
||||||
if (DEBUG && !DEBUG_isLogged) {
|
if (DEBUG && !DEBUG_isLogged) {
|
||||||
DEBUG_isLogged = true;
|
DEBUG_isLogged = true;
|
||||||
@ -143,6 +149,18 @@ const Main: FC<StateProps> = ({
|
|||||||
}
|
}
|
||||||
}, [language, lastSyncTime, loadCountryList, loadEmojiKeywords]);
|
}, [language, lastSyncTime, loadCountryList, loadEmojiKeywords]);
|
||||||
|
|
||||||
|
// Sticker sets
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSynced) {
|
||||||
|
if (!addedSetIds) {
|
||||||
|
loadStickerSets();
|
||||||
|
loadFavoriteStickers();
|
||||||
|
} else {
|
||||||
|
loadAddedStickers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isSynced, addedSetIds, loadStickerSets, loadFavoriteStickers, loadAddedStickers]);
|
||||||
|
|
||||||
// Check version when service chat is ready
|
// Check version when service chat is ready
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (lastSyncTime && isServiceChatReady) {
|
if (lastSyncTime && isServiceChatReady) {
|
||||||
@ -351,6 +369,7 @@ export default memo(withGlobal(
|
|||||||
language,
|
language,
|
||||||
wasTimeFormatSetManually,
|
wasTimeFormatSetManually,
|
||||||
isCallFallbackConfirmOpen: Boolean(global.groupCalls.isFallbackConfirmOpen),
|
isCallFallbackConfirmOpen: Boolean(global.groupCalls.isFallbackConfirmOpen),
|
||||||
|
addedSetIds: global.stickers.added.setIds,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
)(Main));
|
)(Main));
|
||||||
|
|||||||
@ -64,10 +64,7 @@ const StickerPicker: FC<OwnProps & StateProps> = ({
|
|||||||
onStickerSelect,
|
onStickerSelect,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
loadStickerSets,
|
|
||||||
loadRecentStickers,
|
loadRecentStickers,
|
||||||
loadFavoriteStickers,
|
|
||||||
loadAddedStickers,
|
|
||||||
addRecentSticker,
|
addRecentSticker,
|
||||||
unfaveSticker,
|
unfaveSticker,
|
||||||
} = getDispatch();
|
} = getDispatch();
|
||||||
@ -138,18 +135,10 @@ const StickerPicker: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loadAndPlay) {
|
if (loadAndPlay) {
|
||||||
loadStickerSets();
|
|
||||||
loadRecentStickers();
|
loadRecentStickers();
|
||||||
loadFavoriteStickers();
|
|
||||||
sendMessageAction({ type: 'chooseSticker' });
|
sendMessageAction({ type: 'chooseSticker' });
|
||||||
}
|
}
|
||||||
}, [loadAndPlay, loadFavoriteStickers, loadRecentStickers, loadStickerSets, sendMessageAction]);
|
}, [loadAndPlay, loadRecentStickers, sendMessageAction]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (addedSetIds?.length) {
|
|
||||||
loadAddedStickers();
|
|
||||||
}
|
|
||||||
}, [addedSetIds, loadAddedStickers]);
|
|
||||||
|
|
||||||
useHorizontalScroll(headerRef.current);
|
useHorizontalScroll(headerRef.current);
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,9 @@ export default function useStickerTooltip(
|
|||||||
if (isDisabled) return;
|
if (isDisabled) return;
|
||||||
|
|
||||||
if (isAllowed && isSingleEmoji) {
|
if (isAllowed && isSingleEmoji) {
|
||||||
loadStickersForEmoji({ emoji: cleanHtml });
|
loadStickersForEmoji({
|
||||||
|
emoji: IS_EMOJI_SUPPORTED ? cleanHtml : cleanHtml.match(/alt="(.+)"/)?.[1],
|
||||||
|
});
|
||||||
} else if (hasStickers || !isSingleEmoji) {
|
} else if (hasStickers || !isSingleEmoji) {
|
||||||
clearStickersForEmoji();
|
clearStickersForEmoji();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,8 @@ import {
|
|||||||
import searchWords from '../../../util/searchWords';
|
import searchWords from '../../../util/searchWords';
|
||||||
import { selectStickerSet } from '../../selectors';
|
import { selectStickerSet } from '../../selectors';
|
||||||
|
|
||||||
const ADDED_SETS_THROTTLE = 500;
|
const ADDED_SETS_THROTTLE = 200;
|
||||||
const ADDED_SETS_THROTTLE_CHUNK = 50;
|
const ADDED_SETS_THROTTLE_CHUNK = 10;
|
||||||
|
|
||||||
const searchThrottled = throttle((cb) => cb(), 500, false);
|
const searchThrottled = throttle((cb) => cb(), 500, false);
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
ApiChat, ApiFormattedText, ApiMessage, ApiUser, MAIN_THREAD_ID,
|
ApiChat, ApiFormattedText, ApiMessage, ApiUser, MAIN_THREAD_ID,
|
||||||
} from '../../../api/types';
|
} from '../../../api/types';
|
||||||
import { GlobalActions } from '../../../global/types';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CHAT_LIST_LOAD_SLICE, DEBUG, MESSAGE_LIST_SLICE, SERVICE_NOTIFICATIONS_USER_ID,
|
CHAT_LIST_LOAD_SLICE, DEBUG, MESSAGE_LIST_SLICE, SERVICE_NOTIFICATIONS_USER_ID,
|
||||||
@ -44,8 +43,8 @@ addReducer('sync', (global, actions) => {
|
|||||||
void sync(actions.afterSync);
|
void sync(actions.afterSync);
|
||||||
});
|
});
|
||||||
|
|
||||||
addReducer('afterSync', (global, actions) => {
|
addReducer('afterSync', () => {
|
||||||
void afterSync(actions);
|
void afterSync();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function sync(afterSyncCallback: () => void) {
|
async function sync(afterSyncCallback: () => void) {
|
||||||
@ -73,14 +72,12 @@ async function sync(afterSyncCallback: () => void) {
|
|||||||
afterSyncCallback();
|
afterSyncCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function afterSync(actions: GlobalActions) {
|
async function afterSync() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('>>> START AFTER-SYNC');
|
console.log('>>> START AFTER-SYNC');
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.loadFavoriteStickers();
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
loadAndUpdateUsers(),
|
loadAndUpdateUsers(),
|
||||||
loadAndReplaceArchivedChats(),
|
loadAndReplaceArchivedChats(),
|
||||||
|
|||||||
@ -25,6 +25,12 @@ export function selectStickerSetByShortName(global: GlobalState, shortName: stri
|
|||||||
export function selectStickersForEmoji(global: GlobalState, emoji: string) {
|
export function selectStickersForEmoji(global: GlobalState, emoji: string) {
|
||||||
const stickerSets = Object.values(global.stickers.setsById);
|
const stickerSets = Object.values(global.stickers.setsById);
|
||||||
let stickersForEmoji: ApiSticker[] = [];
|
let stickersForEmoji: ApiSticker[] = [];
|
||||||
|
// Favorites
|
||||||
|
global.stickers.favorite.stickers.forEach((sticker) => {
|
||||||
|
if (sticker.emoji === emoji) stickersForEmoji.push(sticker);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Added sets
|
||||||
stickerSets.forEach(({ packs }) => {
|
stickerSets.forEach(({ packs }) => {
|
||||||
if (!packs) {
|
if (!packs) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user