Edit Message: Refactoring (#5172)
This commit is contained in:
parent
e62e78f968
commit
1e822ea234
@ -48,10 +48,10 @@ import {
|
||||
} from '../../config';
|
||||
import { requestMeasure, requestNextMutation } from '../../lib/fasterdom/fasterdom';
|
||||
import {
|
||||
canEditMedia,
|
||||
getAllowedAttachmentOptions,
|
||||
getReactionKey,
|
||||
getStoryKey,
|
||||
hasReplaceableMedia,
|
||||
isChatAdmin,
|
||||
isChatChannel,
|
||||
isChatSuperGroup,
|
||||
@ -433,7 +433,7 @@ const Composer: FC<OwnProps & StateProps> = ({
|
||||
const [isInputHasFocus, markInputHasFocus, unmarkInputHasFocus] = useFlag();
|
||||
const [isAttachMenuOpen, onAttachMenuOpen, onAttachMenuClose] = useFlag();
|
||||
|
||||
const canMediaBeReplaced = editingMessage && hasReplaceableMedia(editingMessage);
|
||||
const canMediaBeReplaced = editingMessage && canEditMedia(editingMessage);
|
||||
|
||||
const { emojiSet, members: groupChatMembers, botCommands: chatBotCommands } = chatFullInfo || {};
|
||||
const chatEmojiSetId = emojiSet?.id;
|
||||
@ -1890,7 +1890,7 @@ const Composer: FC<OwnProps & StateProps> = ({
|
||||
chatId={chatId}
|
||||
threadId={threadId}
|
||||
editingMessage={editingMessage}
|
||||
hasReplaceableMedia={canMediaBeReplaced}
|
||||
canEditMedia={canMediaBeReplaced}
|
||||
isButtonVisible={!activeVoiceRecording}
|
||||
canAttachMedia={canAttachMedia}
|
||||
canAttachPolls={canAttachPolls}
|
||||
|
||||
@ -57,7 +57,7 @@ export type OwnProps = {
|
||||
onPollCreate: NoneToVoidFunction;
|
||||
onMenuOpen: NoneToVoidFunction;
|
||||
onMenuClose: NoneToVoidFunction;
|
||||
hasReplaceableMedia?: boolean;
|
||||
canEditMedia?: boolean;
|
||||
editingMessage?: ApiMessage;
|
||||
};
|
||||
|
||||
@ -80,7 +80,7 @@ const AttachMenu: FC<OwnProps> = ({
|
||||
onMenuOpen,
|
||||
onMenuClose,
|
||||
onPollCreate,
|
||||
hasReplaceableMedia,
|
||||
canEditMedia,
|
||||
editingMessage,
|
||||
}) => {
|
||||
const [isAttachMenuOpen, openAttachMenu, closeAttachMenu] = useFlag();
|
||||
@ -171,7 +171,7 @@ const AttachMenu: FC<OwnProps> = ({
|
||||
return (
|
||||
<div className="AttachMenu">
|
||||
{
|
||||
editingMessage && hasReplaceableMedia ? (
|
||||
editingMessage && canEditMedia ? (
|
||||
<ResponsiveHoverButton
|
||||
id="replace-menu-button"
|
||||
className={isAttachMenuOpen ? 'AttachMenu--button activated' : 'AttachMenu--button'}
|
||||
@ -246,7 +246,7 @@ const AttachMenu: FC<OwnProps> = ({
|
||||
<MenuItem icon="poll" onClick={onPollCreate}>{lang('Poll')}</MenuItem>
|
||||
)}
|
||||
|
||||
{!editingMessage && !hasReplaceableMedia && !isScheduled && bots?.map((bot) => (
|
||||
{!editingMessage && !canEditMedia && !isScheduled && bots?.map((bot) => (
|
||||
<AttachBotItem
|
||||
bot={bot}
|
||||
chatId={chatId}
|
||||
|
||||
@ -57,14 +57,12 @@ export function hasMessageMedia(message: MediaContainer) {
|
||||
));
|
||||
}
|
||||
|
||||
export function hasReplaceableMedia(message: MediaContainer) {
|
||||
export function canEditMedia(message: MediaContainer) {
|
||||
const {
|
||||
text, photo, video, audio, document,
|
||||
photo, video, altVideos, audio, document, text, webPage, ...otherMedia
|
||||
} = message.content;
|
||||
|
||||
if (getMessageVoice(message)) return false;
|
||||
|
||||
return Boolean(text || photo || (video && !video.isGif) || audio || document);
|
||||
return !video?.isRound && !Object.keys(otherMedia).length;
|
||||
}
|
||||
|
||||
export function getMessagePhoto(message: MediaContainer) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user