Allow edits which just remove the quote

This commit is contained in:
Scott Nonnenberg 2024-09-20 10:40:26 +10:00 committed by GitHub
parent 96a2d05906
commit 855b1c03b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 18 additions and 25 deletions

View file

@ -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'),

View file

@ -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({
)}
>
<CompositionInput
clearQuotedMessage={clearQuotedMessage}
conversationId={conversationId}
disabled={isDisabled}
draftBodyRanges={draftBodyRanges}
draftEditMessage={draftEditMessage}
draftText={draftText}
getPreferredBadge={getPreferredBadge}
getQuotedMessage={getQuotedMessage}
i18n={i18n}
inputApi={inputApiRef}
isFormattingEnabled={isFormattingEnabled}
@ -1048,6 +1043,7 @@ export const CompositionArea = memo(function CompositionArea({
onSubmit={handleSubmit}
onTextTooLong={onTextTooLong}
platform={platform}
quotedMessageId={quotedMessageId}
sendCounter={sendCounter}
shouldHidePopovers={shouldHidePopovers}
skinTone={skinTone ?? null}

View file

@ -30,9 +30,7 @@ const useProps = (overrideProps: Partial<Props> = {}): 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> = {}): Props => {
onSubmit: action('onSubmit'),
onTextTooLong: action('onTextTooLong'),
platform: 'darwin',
quotedMessageId: null,
sendCounter: 0,
sortedGroupMembers: overrideProps.sortedGroupMembers ?? [],
skinTone: overrideProps.skinTone ?? null,

View file

@ -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<HTMLElement>) => 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);

View file

@ -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 (
<div className="CompositionTextArea">
<CompositionInput
clearQuotedMessage={shouldNeverBeCalled}
draftBodyRanges={bodyRanges}
draftText={draftText}
getPreferredBadge={getPreferredBadge}
getQuotedMessage={noop}
i18n={i18n}
isActive={isActive}
isFormattingEnabled={isFormattingEnabled}
@ -153,6 +149,7 @@ export function CompositionTextArea({
onTextTooLong={onTextTooLong}
placeholder={placeholder}
platform={platform}
quotedMessageId={null}
scrollerRef={scrollerRef}
sendCounter={0}
theme={theme}

View file

@ -1314,6 +1314,7 @@ export function MediaEditor({
onTextTooLong={onTextTooLong}
placeholder={i18n('icu:MediaEditor__input-placeholder')}
platform={platform}
quotedMessageId={null}
sendCounter={0}
sortedGroupMembers={sortedGroupMembers}
theme={ThemeType.dark}

View file

@ -259,6 +259,7 @@ export function StoryViewsNRepliesModal({
})
}
platform={platform}
quotedMessageId={null}
sendCounter={0}
skinTone={skinTone ?? null}
sortedGroupMembers={sortedGroupMembers ?? null}

View file

@ -1,6 +1,11 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { isValidLink } from '../types/LinkPreview';
export function openLinkInWebBrowser(url: string): void {
if (!isValidLink(url)) {
return;
}
window.location.href = url;
}