Ensure ESC removes quoted reply when drafting

This commit is contained in:
trevor-signal 2024-11-20 11:38:45 -05:00 committed by GitHub
parent fd9e3ea7e0
commit 19f7bff8a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 30 deletions

8
ts/model-types.d.ts vendored
View file

@ -38,6 +38,7 @@ import type { AnyPaymentEvent } from './types/Payment';
import AccessRequiredEnum = Proto.AccessControl.AccessRequired; import AccessRequiredEnum = Proto.AccessControl.AccessRequired;
import MemberRoleEnum = Proto.Member.Role; import MemberRoleEnum = Proto.Member.Role;
import type { MessageRequestResponseEvent } from './types/MessageRequestResponseEvent'; import type { MessageRequestResponseEvent } from './types/MessageRequestResponseEvent';
import type { QuotedMessageForComposerType } from './state/ducks/composer';
export type LastMessageStatus = export type LastMessageStatus =
| 'paused' | 'paused'
@ -97,10 +98,11 @@ export type QuotedMessageType = {
id: number | null; id: number | null;
isGiftBadge?: boolean; isGiftBadge?: boolean;
isViewOnce: boolean; isViewOnce: boolean;
// `messageId` is deprecated
messageId?: string;
referencedMessageNotFound: boolean; referencedMessageNotFound: boolean;
text?: string; text?: string;
/** @deprecated `messageId` is used only in composer state, but still may exist in DB
* records, particularly for messages sent from this device */
messageId?: string;
}; };
type StoryReplyContextType = { type StoryReplyContextType = {
@ -324,7 +326,7 @@ export type DraftEditMessageType = {
body: string; body: string;
preview?: LinkPreviewType; preview?: LinkPreviewType;
targetMessageId: string; targetMessageId: string;
quote?: QuotedMessageType; quote?: QuotedMessageForComposerType['quote'];
}; };
export type ConversationAttributesType = { export type ConversationAttributesType = {

View file

@ -105,19 +105,17 @@ type ComposerStateByConversationType = {
linkPreviewLoading: boolean; linkPreviewLoading: boolean;
linkPreviewResult?: LinkPreviewType; linkPreviewResult?: LinkPreviewType;
messageCompositionId: string; messageCompositionId: string;
quotedMessage?: Pick< quotedMessage?: QuotedMessageForComposerType;
ReadonlyMessageAttributesType,
'conversationId' | 'quote'
>;
sendCounter: number; sendCounter: number;
shouldSendHighQualityAttachments?: boolean; shouldSendHighQualityAttachments?: boolean;
}; };
// eslint-disable-next-line local-rules/type-alias-readonlydeep export type QuotedMessageForComposerType = ReadonlyDeep<{
export type QuotedMessageType = Pick< conversationId: ReadonlyMessageAttributesType['conversationId'];
ReadonlyMessageAttributesType, quote: ReadonlyMessageAttributesType['quote'] & {
'conversationId' | 'quote' messageId?: string;
>; };
}>;
// eslint-disable-next-line local-rules/type-alias-readonlydeep // eslint-disable-next-line local-rules/type-alias-readonlydeep
export type ComposerStateType = { export type ComposerStateType = {
@ -212,7 +210,7 @@ export type SetQuotedMessageActionType = {
type: typeof SET_QUOTED_MESSAGE; type: typeof SET_QUOTED_MESSAGE;
payload: { payload: {
conversationId: string; conversationId: string;
quotedMessage?: QuotedMessageType; quotedMessage?: QuotedMessageForComposerType;
}; };
}; };
@ -713,7 +711,7 @@ export function setQuoteByMessageId(
return async (dispatch, getState) => { return async (dispatch, getState) => {
const conversation = window.ConversationController.get(conversationId); const conversation = window.ConversationController.get(conversationId);
if (!conversation) { if (!conversation) {
throw new Error('sendStickerMessage: No conversation found'); throw new Error('setQuoteByMessageId: No conversation found');
} }
const draftEditMessage = conversation.get('draftEditMessage'); const draftEditMessage = conversation.get('draftEditMessage');
@ -1373,7 +1371,7 @@ function setMediaQualitySetting(
function setQuotedMessage( function setQuotedMessage(
conversationId: string, conversationId: string,
quotedMessage?: QuotedMessageType quotedMessage?: QuotedMessageForComposerType
): SetQuotedMessageActionType { ): SetQuotedMessageActionType {
return { return {
type: SET_QUOTED_MESSAGE, type: SET_QUOTED_MESSAGE,

View file

@ -4,7 +4,10 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import type { StateType } from '../reducer'; import type { StateType } from '../reducer';
import type { ComposerStateType, QuotedMessageType } from '../ducks/composer'; import type {
ComposerStateType,
QuotedMessageForComposerType,
} from '../ducks/composer';
import { getComposerStateForConversation } from '../ducks/composer'; import { getComposerStateForConversation } from '../ducks/composer';
export const getComposerState = (state: StateType): ComposerStateType => export const getComposerState = (state: StateType): ComposerStateType =>
@ -19,6 +22,6 @@ export const getComposerStateForConversationIdSelector = createSelector(
export const getQuotedMessageSelector = createSelector( export const getQuotedMessageSelector = createSelector(
getComposerStateForConversationIdSelector, getComposerStateForConversationIdSelector,
composerStateForConversationIdSelector => composerStateForConversationIdSelector =>
(conversationId: string): QuotedMessageType | undefined => (conversationId: string): QuotedMessageForComposerType | undefined =>
composerStateForConversationIdSelector(conversationId).quotedMessage composerStateForConversationIdSelector(conversationId).quotedMessage
); );

View file

@ -466,7 +466,6 @@ describe('Message', () => {
text: 'hey!', text: 'hey!',
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any, } as any,
@ -478,7 +477,6 @@ describe('Message', () => {
attachments: [], attachments: [],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -502,7 +500,6 @@ describe('Message', () => {
attachments: [], attachments: [],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -531,7 +528,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -564,7 +560,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -584,7 +579,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -619,7 +613,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -639,7 +632,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
}); });
@ -732,7 +724,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
preview: [ preview: [
@ -774,7 +765,6 @@ describe('Message', () => {
], ],
id: 34233, id: 34233,
isViewOnce: false, isViewOnce: false,
messageId: 'message-id',
referencedMessageNotFound: false, referencedMessageNotFound: false,
}, },
preview: [ preview: [

View file

@ -5,7 +5,6 @@ import type { AttachmentType } from '../types/Attachment';
import type { import type {
MessageAttributesType, MessageAttributesType,
QuotedAttachmentType, QuotedAttachmentType,
QuotedMessageType,
} from '../model-types.d'; } from '../model-types.d';
import type { LinkPreviewType } from '../types/message/LinkPreviews'; import type { LinkPreviewType } from '../types/message/LinkPreviews';
import type { StickerType } from '../types/Stickers'; import type { StickerType } from '../types/Stickers';
@ -19,15 +18,23 @@ import { map, take, collect } from './iterables';
import { strictAssert } from './assert'; import { strictAssert } from './assert';
import { getMessageSentTimestamp } from './getMessageSentTimestamp'; import { getMessageSentTimestamp } from './getMessageSentTimestamp';
import { getLocalAttachmentUrl } from './getLocalAttachmentUrl'; import { getLocalAttachmentUrl } from './getLocalAttachmentUrl';
import type { QuotedMessageForComposerType } from '../state/ducks/composer';
export async function makeQuote( export async function makeQuote(
quotedMessage: MessageAttributesType quotedMessage: MessageAttributesType
): Promise<QuotedMessageType> { ): Promise<QuotedMessageForComposerType['quote']> {
const contact = getAuthor(quotedMessage); const contact = getAuthor(quotedMessage);
strictAssert(contact, 'makeQuote: no contact'); strictAssert(contact, 'makeQuote: no contact');
const { attachments, bodyRanges, payment, preview, sticker } = quotedMessage; const {
attachments,
bodyRanges,
id: messageId,
payment,
preview,
sticker,
} = quotedMessage;
const quoteId = getMessageSentTimestamp(quotedMessage, { log }); const quoteId = getMessageSentTimestamp(quotedMessage, { log });
@ -41,6 +48,7 @@ export async function makeQuote(
id: quoteId, id: quoteId,
isViewOnce: isTapToView(quotedMessage), isViewOnce: isTapToView(quotedMessage),
isGiftBadge: isGiftBadge(quotedMessage), isGiftBadge: isGiftBadge(quotedMessage),
messageId,
referencedMessageNotFound: false, referencedMessageNotFound: false,
text: getQuoteBodyText(quotedMessage, quoteId), text: getQuoteBodyText(quotedMessage, quoteId),
}; };