Skip to content

Commit 19f7bff

Browse files
Ensure ESC removes quoted reply when drafting
1 parent fd9e3ea commit 19f7bff

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

ts/model-types.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type { AnyPaymentEvent } from './types/Payment';
3838
import AccessRequiredEnum = Proto.AccessControl.AccessRequired;
3939
import MemberRoleEnum = Proto.Member.Role;
4040
import type { MessageRequestResponseEvent } from './types/MessageRequestResponseEvent';
41+
import type { QuotedMessageForComposerType } from './state/ducks/composer';
4142

4243
export type LastMessageStatus =
4344
| 'paused'
@@ -97,10 +98,11 @@ export type QuotedMessageType = {
9798
id: number | null;
9899
isGiftBadge?: boolean;
99100
isViewOnce: boolean;
100-
// `messageId` is deprecated
101-
messageId?: string;
102101
referencedMessageNotFound: boolean;
103102
text?: string;
103+
/** @deprecated `messageId` is used only in composer state, but still may exist in DB
104+
* records, particularly for messages sent from this device */
105+
messageId?: string;
104106
};
105107

106108
type StoryReplyContextType = {
@@ -324,7 +326,7 @@ export type DraftEditMessageType = {
324326
body: string;
325327
preview?: LinkPreviewType;
326328
targetMessageId: string;
327-
quote?: QuotedMessageType;
329+
quote?: QuotedMessageForComposerType['quote'];
328330
};
329331

330332
export type ConversationAttributesType = {

ts/state/ducks/composer.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,17 @@ type ComposerStateByConversationType = {
105105
linkPreviewLoading: boolean;
106106
linkPreviewResult?: LinkPreviewType;
107107
messageCompositionId: string;
108-
quotedMessage?: Pick<
109-
ReadonlyMessageAttributesType,
110-
'conversationId' | 'quote'
111-
>;
108+
quotedMessage?: QuotedMessageForComposerType;
112109
sendCounter: number;
113110
shouldSendHighQualityAttachments?: boolean;
114111
};
115112

116-
// eslint-disable-next-line local-rules/type-alias-readonlydeep
117-
export type QuotedMessageType = Pick<
118-
ReadonlyMessageAttributesType,
119-
'conversationId' | 'quote'
120-
>;
113+
export type QuotedMessageForComposerType = ReadonlyDeep<{
114+
conversationId: ReadonlyMessageAttributesType['conversationId'];
115+
quote: ReadonlyMessageAttributesType['quote'] & {
116+
messageId?: string;
117+
};
118+
}>;
121119

122120
// eslint-disable-next-line local-rules/type-alias-readonlydeep
123121
export type ComposerStateType = {
@@ -212,7 +210,7 @@ export type SetQuotedMessageActionType = {
212210
type: typeof SET_QUOTED_MESSAGE;
213211
payload: {
214212
conversationId: string;
215-
quotedMessage?: QuotedMessageType;
213+
quotedMessage?: QuotedMessageForComposerType;
216214
};
217215
};
218216

@@ -713,7 +711,7 @@ export function setQuoteByMessageId(
713711
return async (dispatch, getState) => {
714712
const conversation = window.ConversationController.get(conversationId);
715713
if (!conversation) {
716-
throw new Error('sendStickerMessage: No conversation found');
714+
throw new Error('setQuoteByMessageId: No conversation found');
717715
}
718716

719717
const draftEditMessage = conversation.get('draftEditMessage');
@@ -1373,7 +1371,7 @@ function setMediaQualitySetting(
13731371

13741372
function setQuotedMessage(
13751373
conversationId: string,
1376-
quotedMessage?: QuotedMessageType
1374+
quotedMessage?: QuotedMessageForComposerType
13771375
): SetQuotedMessageActionType {
13781376
return {
13791377
type: SET_QUOTED_MESSAGE,

ts/state/selectors/composer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import { createSelector } from 'reselect';
55

66
import type { StateType } from '../reducer';
7-
import type { ComposerStateType, QuotedMessageType } from '../ducks/composer';
7+
import type {
8+
ComposerStateType,
9+
QuotedMessageForComposerType,
10+
} from '../ducks/composer';
811
import { getComposerStateForConversation } from '../ducks/composer';
912

1013
export const getComposerState = (state: StateType): ComposerStateType =>
@@ -19,6 +22,6 @@ export const getComposerStateForConversationIdSelector = createSelector(
1922
export const getQuotedMessageSelector = createSelector(
2023
getComposerStateForConversationIdSelector,
2124
composerStateForConversationIdSelector =>
22-
(conversationId: string): QuotedMessageType | undefined =>
25+
(conversationId: string): QuotedMessageForComposerType | undefined =>
2326
composerStateForConversationIdSelector(conversationId).quotedMessage
2427
);

ts/test-node/types/Message2_test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ describe('Message', () => {
466466
text: 'hey!',
467467
id: 34233,
468468
isViewOnce: false,
469-
messageId: 'message-id',
470469
referencedMessageNotFound: false,
471470
// eslint-disable-next-line @typescript-eslint/no-explicit-any
472471
} as any,
@@ -478,7 +477,6 @@ describe('Message', () => {
478477
attachments: [],
479478
id: 34233,
480479
isViewOnce: false,
481-
messageId: 'message-id',
482480
referencedMessageNotFound: false,
483481
},
484482
});
@@ -502,7 +500,6 @@ describe('Message', () => {
502500
attachments: [],
503501
id: 34233,
504502
isViewOnce: false,
505-
messageId: 'message-id',
506503
referencedMessageNotFound: false,
507504
},
508505
});
@@ -531,7 +528,6 @@ describe('Message', () => {
531528
],
532529
id: 34233,
533530
isViewOnce: false,
534-
messageId: 'message-id',
535531
referencedMessageNotFound: false,
536532
},
537533
});
@@ -564,7 +560,6 @@ describe('Message', () => {
564560
],
565561
id: 34233,
566562
isViewOnce: false,
567-
messageId: 'message-id',
568563
referencedMessageNotFound: false,
569564
},
570565
});
@@ -584,7 +579,6 @@ describe('Message', () => {
584579
],
585580
id: 34233,
586581
isViewOnce: false,
587-
messageId: 'message-id',
588582
referencedMessageNotFound: false,
589583
},
590584
});
@@ -619,7 +613,6 @@ describe('Message', () => {
619613
],
620614
id: 34233,
621615
isViewOnce: false,
622-
messageId: 'message-id',
623616
referencedMessageNotFound: false,
624617
},
625618
});
@@ -639,7 +632,6 @@ describe('Message', () => {
639632
],
640633
id: 34233,
641634
isViewOnce: false,
642-
messageId: 'message-id',
643635
referencedMessageNotFound: false,
644636
},
645637
});
@@ -732,7 +724,6 @@ describe('Message', () => {
732724
],
733725
id: 34233,
734726
isViewOnce: false,
735-
messageId: 'message-id',
736727
referencedMessageNotFound: false,
737728
},
738729
preview: [
@@ -774,7 +765,6 @@ describe('Message', () => {
774765
],
775766
id: 34233,
776767
isViewOnce: false,
777-
messageId: 'message-id',
778768
referencedMessageNotFound: false,
779769
},
780770
preview: [

ts/util/makeQuote.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { AttachmentType } from '../types/Attachment';
55
import type {
66
MessageAttributesType,
77
QuotedAttachmentType,
8-
QuotedMessageType,
98
} from '../model-types.d';
109
import type { LinkPreviewType } from '../types/message/LinkPreviews';
1110
import type { StickerType } from '../types/Stickers';
@@ -19,15 +18,23 @@ import { map, take, collect } from './iterables';
1918
import { strictAssert } from './assert';
2019
import { getMessageSentTimestamp } from './getMessageSentTimestamp';
2120
import { getLocalAttachmentUrl } from './getLocalAttachmentUrl';
21+
import type { QuotedMessageForComposerType } from '../state/ducks/composer';
2222

2323
export async function makeQuote(
2424
quotedMessage: MessageAttributesType
25-
): Promise<QuotedMessageType> {
25+
): Promise<QuotedMessageForComposerType['quote']> {
2626
const contact = getAuthor(quotedMessage);
2727

2828
strictAssert(contact, 'makeQuote: no contact');
2929

30-
const { attachments, bodyRanges, payment, preview, sticker } = quotedMessage;
30+
const {
31+
attachments,
32+
bodyRanges,
33+
id: messageId,
34+
payment,
35+
preview,
36+
sticker,
37+
} = quotedMessage;
3138

3239
const quoteId = getMessageSentTimestamp(quotedMessage, { log });
3340

@@ -41,6 +48,7 @@ export async function makeQuote(
4148
id: quoteId,
4249
isViewOnce: isTapToView(quotedMessage),
4350
isGiftBadge: isGiftBadge(quotedMessage),
51+
messageId,
4452
referencedMessageNotFound: false,
4553
text: getQuoteBodyText(quotedMessage, quoteId),
4654
};

0 commit comments

Comments
 (0)