Attachment Settings: Fix settings updating in drop area (#6296)
This commit is contained in:
parent
f0f9993ebd
commit
d572131f85
@ -466,6 +466,8 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
updateChatSilentPosting,
|
updateChatSilentPosting,
|
||||||
updateInsertingPeerIdMention,
|
updateInsertingPeerIdMention,
|
||||||
updateDraftSuggestedPostInfo,
|
updateDraftSuggestedPostInfo,
|
||||||
|
updateShouldSaveAttachmentsCompression,
|
||||||
|
applyDefaultAttachmentsCompression,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
const oldLang = useOldLang();
|
const oldLang = useOldLang();
|
||||||
@ -551,6 +553,12 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
const hasAttachments = Boolean(attachments.length);
|
const hasAttachments = Boolean(attachments.length);
|
||||||
const [nextText, setNextText] = useState<ApiFormattedText | undefined>(undefined);
|
const [nextText, setNextText] = useState<ApiFormattedText | undefined>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!attachments.length || !attachments) {
|
||||||
|
updateShouldSaveAttachmentsCompression({ shouldSave: false });
|
||||||
|
}
|
||||||
|
}, [attachments]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
canSendStickers, canSendGifs, canAttachMedia, canAttachPolls, canAttachEmbedLinks, canAttachToDoLists,
|
canSendStickers, canSendGifs, canAttachMedia, canAttachPolls, canAttachEmbedLinks, canAttachToDoLists,
|
||||||
canSendVoices, canSendPlainText, canSendAudios, canSendVideos, canSendPhotos, canSendDocuments,
|
canSendVoices, canSendPlainText, canSendAudios, canSendVideos, canSendPhotos, canSendDocuments,
|
||||||
@ -1344,6 +1352,15 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
}, [handleFileSelect, requestedDraftFiles, resetOpenChatWithDraft]);
|
}, [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 handleCustomEmojiSelect = useLastCallback((emoji: ApiSticker, inInputId?: string) => {
|
||||||
const emojiSetId = 'id' in emoji.stickerSetInfo && emoji.stickerSetInfo.id;
|
const emojiSetId = 'id' in emoji.stickerSetInfo && emoji.stickerSetInfo.id;
|
||||||
if (!emoji.isFree && !isCurrentUserPremium && !isChatWithSelf && emojiSetId !== chatEmojiSetId) {
|
if (!emoji.isFree && !isCurrentUserPremium && !isChatWithSelf && emojiSetId !== chatEmojiSetId) {
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import {
|
|||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { requestMutation } from '../../../lib/fasterdom/fasterdom';
|
import { requestMutation } from '../../../lib/fasterdom/fasterdom';
|
||||||
import { getAttachmentMediaType } from '../../../global/helpers';
|
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 { selectCurrentLimit } from '../../../global/selectors/limits';
|
||||||
import { selectSharedSettings } from '../../../global/selectors/sharedState';
|
import { selectSharedSettings } from '../../../global/selectors/sharedState';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
@ -106,6 +106,7 @@ type StateProps = {
|
|||||||
customEmojiForEmoji?: ApiSticker[];
|
customEmojiForEmoji?: ApiSticker[];
|
||||||
captionLimit: number;
|
captionLimit: number;
|
||||||
attachmentSettings: GlobalState['attachmentSettings'];
|
attachmentSettings: GlobalState['attachmentSettings'];
|
||||||
|
shouldSaveAttachmentsCompression?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ATTACHMENT_MODAL_INPUT_ID = 'caption-input-text';
|
const ATTACHMENT_MODAL_INPUT_ID = 'caption-input-text';
|
||||||
@ -133,6 +134,7 @@ const AttachmentModal: FC<OwnProps & StateProps> = ({
|
|||||||
shouldSuggestCustomEmoji,
|
shouldSuggestCustomEmoji,
|
||||||
customEmojiForEmoji,
|
customEmojiForEmoji,
|
||||||
attachmentSettings,
|
attachmentSettings,
|
||||||
|
shouldSaveAttachmentsCompression,
|
||||||
shouldForceCompression,
|
shouldForceCompression,
|
||||||
shouldForceAsFile,
|
shouldForceAsFile,
|
||||||
isForCurrentMessageList,
|
isForCurrentMessageList,
|
||||||
@ -305,7 +307,9 @@ const AttachmentModal: FC<OwnProps & StateProps> = ({
|
|||||||
: isSilent ? onSendSilent : onSend;
|
: isSilent ? onSendSilent : onSend;
|
||||||
send(isSendingCompressed, shouldSendGrouped, isInvertedMedia);
|
send(isSendingCompressed, shouldSendGrouped, isInvertedMedia);
|
||||||
updateAttachmentSettings({
|
updateAttachmentSettings({
|
||||||
shouldCompress: isSendingCompressed,
|
...(shouldSaveAttachmentsCompression && {
|
||||||
|
defaultAttachmentCompression: attachmentSettings.shouldCompress ? 'compress' : 'original',
|
||||||
|
}),
|
||||||
shouldSendGrouped,
|
shouldSendGrouped,
|
||||||
isInvertedMedia,
|
isInvertedMedia,
|
||||||
shouldSendInHighQuality,
|
shouldSendInHighQuality,
|
||||||
@ -784,6 +788,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
attachmentSettings,
|
attachmentSettings,
|
||||||
} = global;
|
} = global;
|
||||||
|
|
||||||
|
const { shouldSaveAttachmentsCompression } = selectTabState(global);
|
||||||
const chatFullInfo = selectChatFullInfo(global, chatId);
|
const chatFullInfo = selectChatFullInfo(global, chatId);
|
||||||
const isChatWithSelf = selectIsChatWithSelf(global, chatId);
|
const isChatWithSelf = selectIsChatWithSelf(global, chatId);
|
||||||
const { shouldSuggestCustomEmoji } = global.settings.byKey;
|
const { shouldSuggestCustomEmoji } = global.settings.byKey;
|
||||||
@ -802,6 +807,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
customEmojiForEmoji: customEmojis.forEmoji.stickers,
|
customEmojiForEmoji: customEmojis.forEmoji.stickers,
|
||||||
captionLimit: selectCurrentLimit(global, 'captionLength'),
|
captionLimit: selectCurrentLimit(global, 'captionLength'),
|
||||||
attachmentSettings,
|
attachmentSettings,
|
||||||
|
shouldSaveAttachmentsCompression,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
)(AttachmentModal));
|
)(AttachmentModal));
|
||||||
|
|||||||
@ -32,7 +32,10 @@ const useClipboardPaste = (
|
|||||||
shouldStripCustomEmoji?: boolean,
|
shouldStripCustomEmoji?: boolean,
|
||||||
onCustomEmojiStripped?: VoidFunction,
|
onCustomEmojiStripped?: VoidFunction,
|
||||||
) => {
|
) => {
|
||||||
const { showNotification } = getActions();
|
const {
|
||||||
|
showNotification,
|
||||||
|
updateShouldSaveAttachmentsCompression,
|
||||||
|
applyDefaultAttachmentsCompression } = getActions();
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -127,6 +130,8 @@ const useClipboardPaste = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSetAttachments) {
|
if (shouldSetAttachments) {
|
||||||
|
updateShouldSaveAttachmentsCompression({ shouldSave: true });
|
||||||
|
applyDefaultAttachmentsCompression();
|
||||||
setAttachments(editedMessage ? newAttachments : (attachments) => attachments.concat(newAttachments));
|
setAttachments(editedMessage ? newAttachments : (attachments) => attachments.concat(newAttachments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 => {
|
addActionHandler('requestEffectInComposer', (global, actions, payload): ActionReturnType => {
|
||||||
const { tabId = getCurrentTabId() } = payload;
|
const { tabId = getCurrentTabId() } = payload;
|
||||||
|
|
||||||
|
|||||||
@ -180,6 +180,7 @@ export const INITIAL_GLOBAL_STATE: GlobalState = {
|
|||||||
|
|
||||||
attachmentSettings: {
|
attachmentSettings: {
|
||||||
shouldCompress: true,
|
shouldCompress: true,
|
||||||
|
defaultAttachmentCompression: 'compress',
|
||||||
shouldSendGrouped: true,
|
shouldSendGrouped: true,
|
||||||
isInvertedMedia: undefined,
|
isInvertedMedia: undefined,
|
||||||
webPageMediaSize: undefined,
|
webPageMediaSize: undefined,
|
||||||
|
|||||||
@ -67,6 +67,7 @@ import type { ReducerAction } from '../../hooks/useReducer';
|
|||||||
import type { P2pMessage } from '../../lib/secret-sauce';
|
import type { P2pMessage } from '../../lib/secret-sauce';
|
||||||
import type {
|
import type {
|
||||||
AccountSettings,
|
AccountSettings,
|
||||||
|
AttachmentCompression,
|
||||||
AudioOrigin,
|
AudioOrigin,
|
||||||
CallSound,
|
CallSound,
|
||||||
ChatListType,
|
ChatListType,
|
||||||
@ -2280,12 +2281,15 @@ export interface ActionPayloads {
|
|||||||
} & WithTabId;
|
} & WithTabId;
|
||||||
|
|
||||||
updateAttachmentSettings: {
|
updateAttachmentSettings: {
|
||||||
|
defaultAttachmentCompression?: AttachmentCompression;
|
||||||
shouldCompress?: boolean;
|
shouldCompress?: boolean;
|
||||||
shouldSendGrouped?: boolean;
|
shouldSendGrouped?: boolean;
|
||||||
isInvertedMedia?: true;
|
isInvertedMedia?: true;
|
||||||
webPageMediaSize?: WebPageMediaSize;
|
webPageMediaSize?: WebPageMediaSize;
|
||||||
shouldSendInHighQuality?: boolean;
|
shouldSendInHighQuality?: boolean;
|
||||||
};
|
};
|
||||||
|
updateShouldSaveAttachmentsCompression: { shouldSave: boolean } & WithTabId;
|
||||||
|
applyDefaultAttachmentsCompression: undefined;
|
||||||
|
|
||||||
saveEffectInDraft: {
|
saveEffectInDraft: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
|
|||||||
@ -54,6 +54,7 @@ import type {
|
|||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
import type {
|
import type {
|
||||||
AccountSettings,
|
AccountSettings,
|
||||||
|
AttachmentCompression,
|
||||||
BotAppPermissions,
|
BotAppPermissions,
|
||||||
ChatListType,
|
ChatListType,
|
||||||
ChatTranslatedMessages,
|
ChatTranslatedMessages,
|
||||||
@ -120,6 +121,7 @@ export type GlobalState = {
|
|||||||
|
|
||||||
attachmentSettings: {
|
attachmentSettings: {
|
||||||
shouldCompress: boolean;
|
shouldCompress: boolean;
|
||||||
|
defaultAttachmentCompression: AttachmentCompression;
|
||||||
shouldSendGrouped: boolean;
|
shouldSendGrouped: boolean;
|
||||||
isInvertedMedia?: true;
|
isInvertedMedia?: true;
|
||||||
webPageMediaSize?: WebPageMediaSize;
|
webPageMediaSize?: WebPageMediaSize;
|
||||||
|
|||||||
@ -888,4 +888,5 @@ export type TabState = {
|
|||||||
isWaitingForStarGiftUpgrade?: true;
|
isWaitingForStarGiftUpgrade?: true;
|
||||||
isWaitingForStarGiftTransfer?: true;
|
isWaitingForStarGiftTransfer?: true;
|
||||||
insertingPeerIdMention?: string;
|
insertingPeerIdMention?: string;
|
||||||
|
shouldSaveAttachmentsCompression?: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -667,6 +667,8 @@ export interface Point {
|
|||||||
|
|
||||||
export type WebPageMediaSize = 'large' | 'small';
|
export type WebPageMediaSize = 'large' | 'small';
|
||||||
|
|
||||||
|
export type AttachmentCompression = 'compress' | 'original';
|
||||||
|
|
||||||
export type StarGiftCategory = number | 'all' | 'limited' | 'stock' | 'resale';
|
export type StarGiftCategory = number | 'all' | 'limited' | 'stock' | 'resale';
|
||||||
|
|
||||||
export type CallSound = (
|
export type CallSound = (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user