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