From 469c08a906e0c0e537556915f540cee15553b5d2 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:31:12 -0500 Subject: [PATCH] Allow edits which just remove the quote Co-authored-by: Scott Nonnenberg --- ts/components/CompositionArea.stories.tsx | 2 -- ts/components/CompositionArea.tsx | 12 ++++-------- ts/components/CompositionInput.stories.tsx | 3 +-- ts/components/CompositionInput.tsx | 14 +++++--------- ts/components/CompositionTextArea.tsx | 5 +---- ts/components/MediaEditor.tsx | 1 + ts/components/StoryViewsNRepliesModal.tsx | 1 + ts/util/openLinkInWebBrowser.ts | 5 +++++ 8 files changed, 18 insertions(+), 25 deletions(-) diff --git a/ts/components/CompositionArea.stories.tsx b/ts/components/CompositionArea.stories.tsx index 955ba424ae..4eee071d55 100644 --- a/ts/components/CompositionArea.stories.tsx +++ b/ts/components/CompositionArea.stories.tsx @@ -81,9 +81,7 @@ export default { onEditorStateChange: action('onEditorStateChange'), onTextTooLong: action('onTextTooLong'), draftText: undefined, - clearQuotedMessage: action('clearQuotedMessage'), getPreferredBadge: () => undefined, - getQuotedMessage: action('getQuotedMessage'), sortedGroupMembers: [], // EmojiButton onPickEmoji: action('onPickEmoji'), diff --git a/ts/components/CompositionArea.tsx b/ts/components/CompositionArea.tsx index 5ae75f02aa..2755d587c2 100644 --- a/ts/components/CompositionArea.tsx +++ b/ts/components/CompositionArea.tsx @@ -193,13 +193,12 @@ export type OwnProps = Readonly<{ export type Props = Pick< CompositionInputProps, - | 'clearQuotedMessage' | 'draftText' | 'draftBodyRanges' | 'getPreferredBadge' - | 'getQuotedMessage' | 'onEditorStateChange' | 'onTextTooLong' + | 'quotedMessageId' | 'sendCounter' | 'sortedGroupMembers' > & @@ -275,11 +274,9 @@ export const CompositionArea = memo(function CompositionArea({ setMediaQualitySetting, shouldSendHighQualityAttachments, // CompositionInput - clearQuotedMessage, draftBodyRanges, draftText, getPreferredBadge, - getQuotedMessage, isFormattingEnabled, onEditorStateChange, onTextTooLong, @@ -720,10 +717,10 @@ export const CompositionArea = memo(function CompositionArea({ const handleEscape = useCallback(() => { if (linkPreviewResult) { onCloseLinkPreview(conversationId); - } else if (draftEditMessage) { - discardEditMessage(conversationId); } else if (quotedMessageId) { setQuoteByMessageId(conversationId, undefined); + } else if (draftEditMessage) { + discardEditMessage(conversationId); } }, [ conversationId, @@ -1024,14 +1021,12 @@ export const CompositionArea = memo(function CompositionArea({ )} > = {}): Props => { draftText: overrideProps.draftText ?? null, draftEditMessage: overrideProps.draftEditMessage ?? null, draftBodyRanges: overrideProps.draftBodyRanges || [], - clearQuotedMessage: action('clearQuotedMessage'), getPreferredBadge: () => undefined, - getQuotedMessage: action('getQuotedMessage'), isActive: true, isFormattingEnabled: overrideProps.isFormattingEnabled === false @@ -45,6 +43,7 @@ const useProps = (overrideProps: Partial = {}): Props => { onSubmit: action('onSubmit'), onTextTooLong: action('onTextTooLong'), platform: 'darwin', + quotedMessageId: null, sendCounter: 0, sortedGroupMembers: overrideProps.sortedGroupMembers ?? [], skinTone: overrideProps.skinTone ?? null, diff --git a/ts/components/CompositionInput.tsx b/ts/components/CompositionInput.tsx index 69003e2e2e..00da41bebc 100644 --- a/ts/components/CompositionInput.tsx +++ b/ts/components/CompositionInput.tsx @@ -71,6 +71,7 @@ import { } from '../quill/formatting/matchers'; import { missingCaseError } from '../util/missingCaseError'; import { AutoSubstituteAsciiEmojis } from '../quill/auto-substitute-ascii-emojis'; +import { dropNull } from '../util/dropNull'; Quill.register('formats/emoji', EmojiBlot); Quill.register('formats/mention', MentionBlot); @@ -139,9 +140,8 @@ export type Props = Readonly<{ ): unknown; onScroll?: (ev: React.UIEvent) => void; platform: string; + quotedMessageId: string | null; shouldHidePopovers: boolean | null; - getQuotedMessage?(): unknown; - clearQuotedMessage?(): unknown; linkPreviewLoading?: boolean; linkPreviewResult: LinkPreviewType | null; onCloseLinkPreview?(conversationId: string): unknown; @@ -153,14 +153,12 @@ const BASE_CLASS_NAME = 'module-composition-input'; export function CompositionInput(props: Props): React.ReactElement { const { children, - clearQuotedMessage, conversationId, disabled, draftBodyRanges, draftEditMessage, draftText, getPreferredBadge, - getQuotedMessage, i18n, inputApi, isFormattingEnabled, @@ -177,6 +175,7 @@ export function CompositionInput(props: Props): React.ReactElement { onSubmit, placeholder, platform, + quotedMessageId, shouldHidePopovers, skinTone, sendCounter, @@ -510,11 +509,6 @@ export function CompositionInput(props: Props): React.ReactElement { } } - if (getQuotedMessage?.()) { - clearQuotedMessage?.(); - return false; - } - return true; }; @@ -598,6 +592,8 @@ export function CompositionInput(props: Props): React.ReactElement { isDirty = true; } else if (!areBodyRangesEqual(bodyRanges, draftEditMessage.bodyRanges)) { isDirty = true; + } else if (dropNull(quotedMessageId) !== draftEditMessage.quote?.id) { + isDirty = true; } propsRef.current.onDirtyChange(isDirty); diff --git a/ts/components/CompositionTextArea.tsx b/ts/components/CompositionTextArea.tsx index ccbb0082dc..bdd968c90f 100644 --- a/ts/components/CompositionTextArea.tsx +++ b/ts/components/CompositionTextArea.tsx @@ -1,11 +1,9 @@ // Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { noop } from 'lodash'; import React from 'react'; import type { LocalizerType } from '../types/I18N'; import type { EmojiPickDataType } from './emoji/EmojiPicker'; -import { shouldNeverBeCalled } from '../util/shouldNeverBeCalled'; import type { InputApi } from './CompositionInput'; import { CompositionInput } from './CompositionInput'; import { EmojiButton } from './emoji/EmojiButton'; @@ -135,11 +133,9 @@ export function CompositionTextArea({ return (