Attachment Settings: Fix settings updating in drop area (#6296)

This commit is contained in:
Alexander Zinchuk 2025-10-08 12:33:23 +02:00
parent f0f9993ebd
commit d572131f85
9 changed files with 62 additions and 3 deletions

View File

@ -466,6 +466,8 @@ const Composer: FC<OwnProps & StateProps> = ({
updateChatSilentPosting,
updateInsertingPeerIdMention,
updateDraftSuggestedPostInfo,
updateShouldSaveAttachmentsCompression,
applyDefaultAttachmentsCompression,
} = getActions();
const oldLang = useOldLang();
@ -551,6 +553,12 @@ const Composer: FC<OwnProps & StateProps> = ({
const hasAttachments = Boolean(attachments.length);
const [nextText, setNextText] = useState<ApiFormattedText | undefined>(undefined);
useEffect(() => {
if (!attachments.length || !attachments) {
updateShouldSaveAttachmentsCompression({ shouldSave: false });
}
}, [attachments]);
const {
canSendStickers, canSendGifs, canAttachMedia, canAttachPolls, canAttachEmbedLinks, canAttachToDoLists,
canSendVoices, canSendPlainText, canSendAudios, canSendVideos, canSendPhotos, canSendDocuments,
@ -1344,6 +1352,15 @@ const Composer: FC<OwnProps & StateProps> = ({
}
}, [handleFileSelect, requestedDraftFiles, resetOpenChatWithDraft]);
useEffect(() => {
if (requestedDraftFiles?.length) {
updateShouldSaveAttachmentsCompression({ shouldSave: true });
applyDefaultAttachmentsCompression();
} else {
updateShouldSaveAttachmentsCompression({ shouldSave: false });
}
}, [requestedDraftFiles, updateShouldSaveAttachmentsCompression, applyDefaultAttachmentsCompression]);
const handleCustomEmojiSelect = useLastCallback((emoji: ApiSticker, inInputId?: string) => {
const emojiSetId = 'id' in emoji.stickerSetInfo && emoji.stickerSetInfo.id;
if (!emoji.isFree && !isCurrentUserPremium && !isChatWithSelf && emojiSetId !== chatEmojiSetId) {

View File

@ -21,7 +21,7 @@ import {
} from '../../../config';
import { requestMutation } from '../../../lib/fasterdom/fasterdom';
import { getAttachmentMediaType } from '../../../global/helpers';
import { selectChatFullInfo, selectIsChatWithSelf } from '../../../global/selectors';
import { selectChatFullInfo, selectIsChatWithSelf, selectTabState } from '../../../global/selectors';
import { selectCurrentLimit } from '../../../global/selectors/limits';
import { selectSharedSettings } from '../../../global/selectors/sharedState';
import buildClassName from '../../../util/buildClassName';
@ -106,6 +106,7 @@ type StateProps = {
customEmojiForEmoji?: ApiSticker[];
captionLimit: number;
attachmentSettings: GlobalState['attachmentSettings'];
shouldSaveAttachmentsCompression?: boolean;
};
const ATTACHMENT_MODAL_INPUT_ID = 'caption-input-text';
@ -133,6 +134,7 @@ const AttachmentModal: FC<OwnProps & StateProps> = ({
shouldSuggestCustomEmoji,
customEmojiForEmoji,
attachmentSettings,
shouldSaveAttachmentsCompression,
shouldForceCompression,
shouldForceAsFile,
isForCurrentMessageList,
@ -305,7 +307,9 @@ const AttachmentModal: FC<OwnProps & StateProps> = ({
: isSilent ? onSendSilent : onSend;
send(isSendingCompressed, shouldSendGrouped, isInvertedMedia);
updateAttachmentSettings({
shouldCompress: isSendingCompressed,
...(shouldSaveAttachmentsCompression && {
defaultAttachmentCompression: attachmentSettings.shouldCompress ? 'compress' : 'original',
}),
shouldSendGrouped,
isInvertedMedia,
shouldSendInHighQuality,
@ -784,6 +788,7 @@ export default memo(withGlobal<OwnProps>(
attachmentSettings,
} = global;
const { shouldSaveAttachmentsCompression } = selectTabState(global);
const chatFullInfo = selectChatFullInfo(global, chatId);
const isChatWithSelf = selectIsChatWithSelf(global, chatId);
const { shouldSuggestCustomEmoji } = global.settings.byKey;
@ -802,6 +807,7 @@ export default memo(withGlobal<OwnProps>(
customEmojiForEmoji: customEmojis.forEmoji.stickers,
captionLimit: selectCurrentLimit(global, 'captionLength'),
attachmentSettings,
shouldSaveAttachmentsCompression,
};
},
)(AttachmentModal));

View File

@ -32,7 +32,10 @@ const useClipboardPaste = (
shouldStripCustomEmoji?: boolean,
onCustomEmojiStripped?: VoidFunction,
) => {
const { showNotification } = getActions();
const {
showNotification,
updateShouldSaveAttachmentsCompression,
applyDefaultAttachmentsCompression } = getActions();
const lang = useLang();
useEffect(() => {
@ -127,6 +130,8 @@ const useClipboardPaste = (
}
if (shouldSetAttachments) {
updateShouldSaveAttachmentsCompression({ shouldSave: true });
applyDefaultAttachmentsCompression();
setAttachments(editedMessage ? newAttachments : (attachments) => attachments.concat(newAttachments));
}

View File

@ -544,6 +544,27 @@ addActionHandler('updateAttachmentSettings', (global, actions, payload): ActionR
};
});
addActionHandler('updateShouldSaveAttachmentsCompression', (global, actions, payload): ActionReturnType => {
const { shouldSave, tabId = getCurrentTabId() } = payload;
return updateTabState(global, {
shouldSaveAttachmentsCompression: shouldSave,
}, tabId);
});
addActionHandler('applyDefaultAttachmentsCompression', (global): ActionReturnType => {
const { defaultAttachmentCompression } = global.attachmentSettings;
const shouldCompress = defaultAttachmentCompression === 'compress';
return {
...global,
attachmentSettings: {
...global.attachmentSettings,
shouldCompress,
},
};
});
addActionHandler('requestEffectInComposer', (global, actions, payload): ActionReturnType => {
const { tabId = getCurrentTabId() } = payload;

View File

@ -180,6 +180,7 @@ export const INITIAL_GLOBAL_STATE: GlobalState = {
attachmentSettings: {
shouldCompress: true,
defaultAttachmentCompression: 'compress',
shouldSendGrouped: true,
isInvertedMedia: undefined,
webPageMediaSize: undefined,

View File

@ -67,6 +67,7 @@ import type { ReducerAction } from '../../hooks/useReducer';
import type { P2pMessage } from '../../lib/secret-sauce';
import type {
AccountSettings,
AttachmentCompression,
AudioOrigin,
CallSound,
ChatListType,
@ -2280,12 +2281,15 @@ export interface ActionPayloads {
} & WithTabId;
updateAttachmentSettings: {
defaultAttachmentCompression?: AttachmentCompression;
shouldCompress?: boolean;
shouldSendGrouped?: boolean;
isInvertedMedia?: true;
webPageMediaSize?: WebPageMediaSize;
shouldSendInHighQuality?: boolean;
};
updateShouldSaveAttachmentsCompression: { shouldSave: boolean } & WithTabId;
applyDefaultAttachmentsCompression: undefined;
saveEffectInDraft: {
chatId: string;

View File

@ -54,6 +54,7 @@ import type {
} from '../../api/types';
import type {
AccountSettings,
AttachmentCompression,
BotAppPermissions,
ChatListType,
ChatTranslatedMessages,
@ -120,6 +121,7 @@ export type GlobalState = {
attachmentSettings: {
shouldCompress: boolean;
defaultAttachmentCompression: AttachmentCompression;
shouldSendGrouped: boolean;
isInvertedMedia?: true;
webPageMediaSize?: WebPageMediaSize;

View File

@ -888,4 +888,5 @@ export type TabState = {
isWaitingForStarGiftUpgrade?: true;
isWaitingForStarGiftTransfer?: true;
insertingPeerIdMention?: string;
shouldSaveAttachmentsCompression?: boolean;
};

View File

@ -667,6 +667,8 @@ export interface Point {
export type WebPageMediaSize = 'large' | 'small';
export type AttachmentCompression = 'compress' | 'original';
export type StarGiftCategory = number | 'all' | 'limited' | 'stock' | 'resale';
export type CallSound = (