Settings: Allow to turn off dynamic order for sticker packs (#3151)

This commit is contained in:
Alexander Zinchuk 2023-05-03 21:33:29 +04:00
parent dda81b5962
commit 48bb2d08a6
10 changed files with 57 additions and 19 deletions

View File

@ -233,7 +233,7 @@ export function sendMessage(
groupedId, groupedId,
noWebPage, noWebPage,
sendAs, sendAs,
shouldUpdateStickerSetsOrder, shouldUpdateStickerSetOrder,
}: { }: {
chat: ApiChat; chat: ApiChat;
text?: string; text?: string;
@ -250,7 +250,7 @@ export function sendMessage(
groupedId?: string; groupedId?: string;
noWebPage?: boolean; noWebPage?: boolean;
sendAs?: ApiUser | ApiChat; sendAs?: ApiUser | ApiChat;
shouldUpdateStickerSetsOrder?: boolean; shouldUpdateStickerSetOrder?: boolean;
}, },
onProgress?: ApiOnProgress, onProgress?: ApiOnProgress,
) { ) {
@ -355,7 +355,7 @@ export function sendMessage(
...(media && { media }), ...(media && { media }),
...(noWebPage && { noWebpage: noWebPage }), ...(noWebPage && { noWebpage: noWebPage }),
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }), ...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
...(shouldUpdateStickerSetsOrder && { updateStickersetsOrder: shouldUpdateStickerSetsOrder }), ...(shouldUpdateStickerSetOrder && { updateStickersetsOrder: shouldUpdateStickerSetOrder }),
}), false, true, true); }), false, true, true);
if (update) handleLocalMessageUpdate(localMessage, update); if (update) handleLocalMessageUpdate(localMessage, update);
} catch (error: any) { } catch (error: any) {

View File

@ -50,6 +50,7 @@ type StateProps = {
shouldSchedule?: boolean; shouldSchedule?: boolean;
isSavedMessages?: boolean; isSavedMessages?: boolean;
isCurrentUserPremium?: boolean; isCurrentUserPremium?: boolean;
shouldUpdateStickerSetOrder?: boolean;
}; };
const INTERSECTION_THROTTLE = 200; const INTERSECTION_THROTTLE = 200;
@ -64,6 +65,7 @@ const StickerSetModal: FC<OwnProps & StateProps> = ({
shouldSchedule, shouldSchedule,
isSavedMessages, isSavedMessages,
isCurrentUserPremium, isCurrentUserPremium,
shouldUpdateStickerSetOrder,
onClose, onClose,
}) => { }) => {
const { const {
@ -120,10 +122,14 @@ const StickerSetModal: FC<OwnProps & StateProps> = ({
onClose(); onClose();
}); });
} else { } else {
sendMessage({ sticker, isSilent, shouldUpdateStickerSetsOrder: isAdded }); sendMessage({
sticker,
isSilent,
shouldUpdateStickerSetOrder: shouldUpdateStickerSetOrder && isAdded,
});
onClose(); onClose();
} }
}, [onClose, requestCalendar, sendMessage, shouldSchedule, isAdded]); }, [onClose, requestCalendar, sendMessage, shouldSchedule, isAdded, shouldUpdateStickerSetOrder]);
const handleButtonClick = useCallback(() => { const handleButtonClick = useCallback(() => {
if (renderingStickerSet) { if (renderingStickerSet) {
@ -263,6 +269,7 @@ export default memo(withGlobal<OwnProps>(
shouldSchedule: selectShouldSchedule(global), shouldSchedule: selectShouldSchedule(global),
stickerSet, stickerSet,
isCurrentUserPremium: selectIsCurrentUserPremium(global), isCurrentUserPremium: selectIsCurrentUserPremium(global),
shouldUpdateStickerSetOrder: global.settings.byKey.shouldUpdateStickerSetOrder,
}; };
}, },
)(StickerSetModal)); )(StickerSetModal));

View File

@ -37,7 +37,7 @@ type OwnProps = {
type StateProps = type StateProps =
Pick<ISettings, ( Pick<ISettings, (
'shouldSuggestStickers' 'shouldSuggestStickers' | 'shouldUpdateStickerSetOrder'
)> & { )> & {
addedSetIds?: string[]; addedSetIds?: string[];
customEmojiSetIds?: string[]; customEmojiSetIds?: string[];
@ -54,6 +54,7 @@ const SettingsStickers: FC<OwnProps & StateProps> = ({
stickerSetsById, stickerSetsById,
defaultReaction, defaultReaction,
shouldSuggestStickers, shouldSuggestStickers,
shouldUpdateStickerSetOrder,
availableReactions, availableReactions,
canPlayAnimatedEmojis, canPlayAnimatedEmojis,
onReset, onReset,
@ -75,6 +76,10 @@ const SettingsStickers: FC<OwnProps & StateProps> = ({
}); });
}, [openStickerSet]); }, [openStickerSet]);
const handleSuggestStickerSetOrderChange = useCallback((newValue: boolean) => {
setSettingOption({ shouldUpdateStickerSetOrder: newValue });
}, [setSettingOption]);
const handleSuggestStickersChange = useCallback((newValue: boolean) => { const handleSuggestStickersChange = useCallback((newValue: boolean) => {
setSettingOption({ shouldSuggestStickers: newValue }); setSettingOption({ shouldSuggestStickers: newValue });
}, [setSettingOption]); }, [setSettingOption]);
@ -121,6 +126,19 @@ const SettingsStickers: FC<OwnProps & StateProps> = ({
</ListItem> </ListItem>
)} )}
</div> </div>
<div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
{lang('InstalledStickers.DynamicPackOrder')}
</h4>
<Checkbox
label={lang('InstalledStickers.DynamicPackOrder')}
checked={shouldUpdateStickerSetOrder}
onCheck={handleSuggestStickerSetOrderChange}
/>
<p className="settings-item-description mt-3" dir="auto">
{lang('InstalledStickers.DynamicPackOrderInfo')}
</p>
</div>
{stickerSets && ( {stickerSets && (
<div className="settings-item"> <div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}> <h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
@ -151,6 +169,7 @@ export default memo(withGlobal<OwnProps>(
return { return {
...pick(global.settings.byKey, [ ...pick(global.settings.byKey, [
'shouldSuggestStickers', 'shouldSuggestStickers',
'shouldUpdateStickerSetOrder',
]), ]),
addedSetIds: global.stickers.added.setIds, addedSetIds: global.stickers.added.setIds,
customEmojiSetIds: global.customEmojis.added.setIds, customEmojiSetIds: global.customEmojis.added.setIds,

View File

@ -204,6 +204,7 @@ type StateProps =
canSendVoiceByPrivacy?: boolean; canSendVoiceByPrivacy?: boolean;
attachmentSettings: GlobalState['attachmentSettings']; attachmentSettings: GlobalState['attachmentSettings'];
slowMode?: ApiChatFullInfo['slowMode']; slowMode?: ApiChatFullInfo['slowMode'];
shouldUpdateStickerSetOrder?: boolean;
} }
& Pick<GlobalState, 'connectionState'>; & Pick<GlobalState, 'connectionState'>;
@ -289,6 +290,7 @@ const Composer: FC<OwnProps & StateProps> = ({
attachmentSettings, attachmentSettings,
theme, theme,
slowMode, slowMode,
shouldUpdateStickerSetOrder,
}) => { }) => {
const { const {
sendMessage, sendMessage,
@ -757,7 +759,7 @@ const Composer: FC<OwnProps & StateProps> = ({
entities, entities,
scheduledAt, scheduledAt,
isSilent, isSilent,
shouldUpdateStickerSetsOrder: true, shouldUpdateStickerSetOrder,
attachments: prepareAttachmentsToSend(attachmentsToSend, sendCompressed), attachments: prepareAttachmentsToSend(attachmentsToSend, sendCompressed),
shouldGroupMessages: sendGrouped, shouldGroupMessages: sendGrouped,
}); });
@ -772,7 +774,7 @@ const Composer: FC<OwnProps & StateProps> = ({
}); });
}, [ }, [
attachmentSettings.shouldCompress, attachmentSettings.shouldSendGrouped, connectionState, getHtml, attachmentSettings.shouldCompress, attachmentSettings.shouldSendGrouped, connectionState, getHtml,
validateTextLength, checkSlowMode, sendMessage, clearDraft, chatId, resetComposer, validateTextLength, checkSlowMode, sendMessage, clearDraft, chatId, resetComposer, shouldUpdateStickerSetOrder,
]); ]);
const handleSendAttachments = useCallback(( const handleSendAttachments = useCallback((
@ -834,7 +836,7 @@ const Composer: FC<OwnProps & StateProps> = ({
entities, entities,
scheduledAt, scheduledAt,
isSilent, isSilent,
shouldUpdateStickerSetsOrder: true, shouldUpdateStickerSetOrder,
}); });
} }
@ -860,6 +862,7 @@ const Composer: FC<OwnProps & StateProps> = ({
}, [ }, [
connectionState, attachments, activeVoiceRecording, getHtml, isForwarding, validateTextLength, clearDraft, connectionState, attachments, activeVoiceRecording, getHtml, isForwarding, validateTextLength, clearDraft,
chatId, stopRecordingVoice, sendAttachments, checkSlowMode, sendMessage, forwardMessages, resetComposer, chatId, stopRecordingVoice, sendAttachments, checkSlowMode, sendMessage, forwardMessages, resetComposer,
shouldUpdateStickerSetOrder,
]); ]);
const handleClickBotMenu = useCallback(() => { const handleClickBotMenu = useCallback(() => {
@ -972,7 +975,7 @@ const Composer: FC<OwnProps & StateProps> = ({
isSilent?: boolean, isSilent?: boolean,
isScheduleRequested?: boolean, isScheduleRequested?: boolean,
shouldPreserveInput = false, shouldPreserveInput = false,
shouldUpdateStickerSetsOrder?: boolean, canUpdateStickerSetsOrder?: boolean,
) => { ) => {
sticker = { sticker = {
...sticker, ...sticker,
@ -989,14 +992,18 @@ const Composer: FC<OwnProps & StateProps> = ({
}); });
}); });
} else { } else {
sendMessage({ sticker, isSilent, shouldUpdateStickerSetsOrder }); sendMessage({
sticker,
isSilent,
shouldUpdateStickerSetOrder: shouldUpdateStickerSetOrder && canUpdateStickerSetsOrder,
});
requestMeasure(() => { requestMeasure(() => {
resetComposer(shouldPreserveInput); resetComposer(shouldPreserveInput);
}); });
} }
}, [ }, [
shouldSchedule, forceShowSymbolMenu, requestCalendar, cancelForceShowSymbolMenu, handleMessageSchedule, shouldSchedule, forceShowSymbolMenu, requestCalendar, cancelForceShowSymbolMenu, handleMessageSchedule,
resetComposer, sendMessage, resetComposer, sendMessage, shouldUpdateStickerSetOrder,
]); ]);
const handleInlineBotSelect = useCallback(( const handleInlineBotSelect = useCallback((
@ -1581,7 +1588,9 @@ export default memo(withGlobal<OwnProps>(
const messageWithActualBotKeyboard = (isChatWithBot || !isChatWithUser) const messageWithActualBotKeyboard = (isChatWithBot || !isChatWithUser)
&& selectNewestMessageWithBotKeyboardButtons(global, chatId, threadId); && selectNewestMessageWithBotKeyboardButtons(global, chatId, threadId);
const scheduledIds = selectScheduledIds(global, chatId, threadId); const scheduledIds = selectScheduledIds(global, chatId, threadId);
const { language, shouldSuggestStickers, shouldSuggestCustomEmoji } = global.settings.byKey; const {
language, shouldSuggestStickers, shouldSuggestCustomEmoji, shouldUpdateStickerSetOrder,
} = global.settings.byKey;
const baseEmojiKeywords = global.emojiKeywords[BASE_EMOJI_KEYWORD_LANG]; const baseEmojiKeywords = global.emojiKeywords[BASE_EMOJI_KEYWORD_LANG];
const emojiKeywords = language !== BASE_EMOJI_KEYWORD_LANG ? global.emojiKeywords[language] : undefined; const emojiKeywords = language !== BASE_EMOJI_KEYWORD_LANG ? global.emojiKeywords[language] : undefined;
const botKeyboardMessageId = messageWithActualBotKeyboard ? messageWithActualBotKeyboard.id : undefined; const botKeyboardMessageId = messageWithActualBotKeyboard ? messageWithActualBotKeyboard.id : undefined;
@ -1645,6 +1654,7 @@ export default memo(withGlobal<OwnProps>(
contentToBeScheduled: tabState.contentToBeScheduled, contentToBeScheduled: tabState.contentToBeScheduled,
shouldSuggestStickers, shouldSuggestStickers,
shouldSuggestCustomEmoji, shouldSuggestCustomEmoji,
shouldUpdateStickerSetOrder,
recentEmojis: global.recentEmojis, recentEmojis: global.recentEmojis,
baseEmojiKeywords: baseEmojiKeywords?.keywords, baseEmojiKeywords: baseEmojiKeywords?.keywords,
emojiKeywords: emojiKeywords?.keywords, emojiKeywords: emojiKeywords?.keywords,

View File

@ -53,7 +53,7 @@ type OwnProps = {
loadAndPlay: boolean; loadAndPlay: boolean;
canSendStickers?: boolean; canSendStickers?: boolean;
onStickerSelect: ( onStickerSelect: (
sticker: ApiSticker, isSilent?: boolean, shouldSchedule?: boolean, shouldUpdateStickerSetsOrder?: boolean, sticker: ApiSticker, isSilent?: boolean, shouldSchedule?: boolean, canUpdateStickerSetsOrder?: boolean,
) => void; ) => void;
}; };

View File

@ -47,7 +47,7 @@ export type OwnProps = {
isSilent?: boolean, isSilent?: boolean,
shouldSchedule?: boolean, shouldSchedule?: boolean,
shouldPreserveInput?: boolean, shouldPreserveInput?: boolean,
shouldUpdateStickerSetsOrder?: boolean, canUpdateStickerSetsOrder?: boolean,
) => void; ) => void;
onGifSelect?: (gif: ApiVideo, isSilent?: boolean, shouldSchedule?: boolean) => void; onGifSelect?: (gif: ApiVideo, isSilent?: boolean, shouldSchedule?: boolean) => void;
onRemoveSymbol: () => void; onRemoveSymbol: () => void;
@ -198,9 +198,9 @@ const SymbolMenu: FC<OwnProps & StateProps> = ({
}, [onClose, onSearchOpen]); }, [onClose, onSearchOpen]);
const handleStickerSelect = useCallback(( const handleStickerSelect = useCallback((
sticker: ApiSticker, isSilent?: boolean, shouldSchedule?: boolean, shouldUpdateStickerSetsOrder?: boolean, sticker: ApiSticker, isSilent?: boolean, shouldSchedule?: boolean, canUpdateStickerSetsOrder?: boolean,
) => { ) => {
onStickerSelect?.(sticker, isSilent, shouldSchedule, true, shouldUpdateStickerSetsOrder); onStickerSelect?.(sticker, isSilent, shouldSchedule, true, canUpdateStickerSetsOrder);
}, [onStickerSelect]); }, [onStickerSelect]);
const lang = useLang(); const lang = useLang();

View File

@ -35,7 +35,7 @@ type OwnProps = {
isSilent?: boolean, isSilent?: boolean,
shouldSchedule?: boolean, shouldSchedule?: boolean,
shouldPreserveInput?: boolean, shouldPreserveInput?: boolean,
shouldUpdateStickerSetsOrder?: boolean canUpdateStickerSetsOrder?: boolean
) => void; ) => void;
onGifSelect?: (gif: ApiVideo, isSilent?: boolean, shouldSchedule?: boolean) => void; onGifSelect?: (gif: ApiVideo, isSilent?: boolean, shouldSchedule?: boolean) => void;
onRemoveSymbol: VoidFunction; onRemoveSymbol: VoidFunction;

View File

@ -214,6 +214,7 @@ export const INITIAL_GLOBAL_STATE: GlobalState = {
notificationSoundVolume: 5, notificationSoundVolume: 5,
shouldSuggestStickers: true, shouldSuggestStickers: true,
shouldSuggestCustomEmoji: true, shouldSuggestCustomEmoji: true,
shouldUpdateStickerSetOrder: true,
language: 'en', language: 'en',
timeFormat: '24h', timeFormat: '24h',
wasTimeFormatSetManually: false, wasTimeFormatSetManually: false,

View File

@ -1178,7 +1178,7 @@ export interface ActionPayloads {
gif?: ApiVideo; gif?: ApiVideo;
poll?: ApiNewPoll; poll?: ApiNewPoll;
contact?: Partial<ApiContact>; contact?: Partial<ApiContact>;
shouldUpdateStickerSetsOrder?: boolean; shouldUpdateStickerSetOrder?: boolean;
shouldGroupMessages?: boolean; shouldGroupMessages?: boolean;
} & WithTabId; } & WithTabId;
cancelSendingMessage: { cancelSendingMessage: {

View File

@ -86,6 +86,7 @@ export interface ISettings extends NotifySettings, Record<string, any> {
autoLoadFileMaxSizeMb: number; autoLoadFileMaxSizeMb: number;
shouldSuggestStickers: boolean; shouldSuggestStickers: boolean;
shouldSuggestCustomEmoji: boolean; shouldSuggestCustomEmoji: boolean;
shouldUpdateStickerSetOrder: boolean;
hasPassword?: boolean; hasPassword?: boolean;
languages?: ApiLanguage[]; languages?: ApiLanguage[];
language: LangCode; language: LangCode;