diff --git a/src/components/chat/contextMenu.ts b/src/components/chat/contextMenu.ts index 33c1cc47a..f9545abbd 100644 --- a/src/components/chat/contextMenu.ts +++ b/src/components/chat/contextMenu.ts @@ -574,10 +574,14 @@ export default class ChatContextMenu { }]; } + private getMessageWithText() { + return (this.albumMessages && getAlbumText(this.albumMessages)) || this.message; + } + private getUniqueCustomEmojisFromMessage() { const docIds: DocId[] = []; - const message = this.albumMessages ? getAlbumText(this.albumMessages) || this.message : this.message; + const message = this.getMessageWithText(); const entities = (message as Message.message).entities; if(entities) { @@ -882,7 +886,8 @@ export default class ChatContextMenu { }; private onEditClick = () => { - this.chat.input.initMessageEditing(this.mid); + const message = this.getMessageWithText(); + this.chat.input.initMessageEditing(this.isTargetAGroupedItem ? this.mid : message.mid); }; private onCopyClick = async() => { diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index 4c42bb3c9..08e432e35 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -106,6 +106,8 @@ import isSelectionEmpty from '../../helpers/dom/isSelectionEmpty'; import wrapEmojiText from '../../lib/richTextProcessor/wrapEmojiText'; import getAttachMenuBotIcon from '../../lib/appManagers/utils/attachMenuBots/getAttachMenuBotIcon'; import TelegramWebView from '../telegramWebView'; +import forEachReverse from '../../helpers/array/forEachReverse'; +import {MARKDOWN_ENTITIES} from '../../lib/richTextProcessor'; const RECORD_MIN_TIME = 500; const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.'; @@ -1215,11 +1217,11 @@ export default class ChatInput { } } - public getCurrentInputAsDraft() { + public getCurrentInputAsDraft(ignoreEmptyValue?: boolean) { const {value, entities} = getRichValueWithCaret(this.messageInputField.input, true, false); let draft: DraftMessage.draftMessage; - if(value.length || this.replyToMsgId) { + if((value.length || ignoreEmptyValue) || this.replyToMsgId) { draft = { _: 'draftMessage', date: tsNow(true), @@ -2501,13 +2503,28 @@ export default class ChatInput { if(this.helperType === 'edit' && !force) { const message = this.editMessage; - const draft = this.getCurrentInputAsDraft(); + const draft = this.getCurrentInputAsDraft(true); if(draft) { delete draft.pFlags.no_webpage; } // const value = parseMarkdown(this.messageInputField.value, []); // if(message.message !== value) { - if(!draftsAreEqual(draft, {...message, _: 'draftMessage'} as any)) { + const originalDraft = {...message, _: 'draftMessage'} as DraftMessage.draftMessage; + if(originalDraft.entities?.length) { + const canPassEntitiesTypes = new Set(Object.values(MARKDOWN_ENTITIES)); + originalDraft.entities = originalDraft.entities.slice(); + forEachReverse(originalDraft.entities, (entity, idx, arr) => { + if(!canPassEntitiesTypes.has(entity._)) { + arr.splice(idx, 1); + } + }); + + if(!originalDraft.entities.length) { + delete originalDraft.entities; + } + } + + if(!draftsAreEqual(draft, originalDraft)) { new PopupPeer('discard-editing', { buttons: [{ langKey: 'Alert.Confirm.Discard',