Skip to content

Commit 27c4be2

Browse files
author
Ioan Moldovan
authored
#5906 Keep original reply message when switching to secure mode (#5914)
* fix: keep original reply message when switching to secure mode * fix: message id get
1 parent bd5c8af commit 27c4be2

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

extension/js/content_scripts/webmail/gmail/gmail-element-replacer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ export class GmailElementReplacer extends WebmailElementReplacer {
619619
return from ? Str.parseEmail(from) : undefined;
620620
};
621621

622-
private getLastMsgReplyParams = (convoRootEl: JQuery, replyOption?: ReplyOption): FactoryReplyParams => {
623-
return { replyMsgId: this.determineMsgId($(convoRootEl).find(this.sel.msgInner).last()), replyOption };
622+
private getLastMsgReplyParams = (convoRootEl: JQuery, replyOption?: ReplyOption, replyBoxMessageId?: string | null): FactoryReplyParams => {
623+
return { replyMsgId: replyBoxMessageId ?? this.determineMsgId($(convoRootEl).find(this.sel.msgInner).last()), replyOption };
624624
};
625625

626626
private getConvoRootEl = (anyInnerElement: HTMLElement) => {
@@ -646,9 +646,13 @@ export class GmailElementReplacer extends WebmailElementReplacer {
646646
// removing this line will cause unexpected draft creation bug reappear
647647
// https://github.com/FlowCrypt/flowcrypt-browser/issues/5616#issuecomment-1972897692
648648
this.replyOption = undefined;
649+
// Try to get message id from plain reply box
650+
// https://github.com/FlowCrypt/flowcrypt-browser/issues/5906
651+
const replyBoxMessageId = newReplyBoxes[0].closest('.gA.gt')?.previousElementSibling?.getAttribute('data-legacy-message-id');
652+
649653
// cache for subseqent loop runs
650654
const convoRootEl = this.getConvoRootEl(newReplyBoxes[0]);
651-
const replyParams = this.getLastMsgReplyParams(convoRootEl);
655+
const replyParams = this.getLastMsgReplyParams(convoRootEl, undefined, replyBoxMessageId);
652656
if (msgId) {
653657
replyParams.replyMsgId = msgId;
654658
}

test/source/tests/gmail.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,32 @@ export const defineGmailTests = (testVariant: TestVariant, testWithBrowser: Test
402402
})
403403
);
404404

405+
// https://github.com/FlowCrypt/flowcrypt-browser/issues/5906
406+
test(
407+
'mail.google.com - Keep original reply message when switching to secure mode',
408+
testWithBrowser(async (t, browser) => {
409+
await BrowserRecipe.setUpCommonAcct(t, browser, 'ci.tests.gmail');
410+
const gmailPage = await openGmailPage(t, browser);
411+
await gotoGmailPage(gmailPage, '/FMfcgzGqRGfPBbNLWvfPvDbxnHBwkdGf'); // plain convo
412+
await Util.sleep(30);
413+
await gmailPage.waitAndClick('[role="listitem"] .adf.ads', { delay: 1 }); // click first message of thread
414+
await Util.sleep(3);
415+
const messages = await gmailPage.target.$$('[role="listitem"] .adn.ads');
416+
const plainReplyButton = await messages[0].$('[data-tooltip="Reply"]');
417+
await Util.sleep(1);
418+
await plainReplyButton!.click();
419+
await gmailPage.waitAndClick('#switch_to_encrypted_reply'); // Switch to encrypted compose
420+
await Util.sleep(2);
421+
await gmailPage.waitAll('.reply_message');
422+
await pageHasSecureReplyContainer(t, browser, gmailPage, { isReplyPromptAccepted: true, composeFrameCount: 2 });
423+
const replyBox = await gmailPage.getFrame(['/chrome/elements/compose.htm', '&skipClickPrompt=___cu_true___'], { sleep: 5 });
424+
await Util.sleep(3);
425+
await replyBox.waitAndClick('@action-expand-quoted-text');
426+
// Check if quoted message doesn't contain last message
427+
expect(await replyBox.read('@input-body')).to.not.contain(`Here's reply`);
428+
})
429+
);
430+
405431
test(
406432
'mail.google.com - switch to encrypted reply for middle message',
407433
testWithBrowser(async (t, browser) => {

0 commit comments

Comments
 (0)