@@ -38,7 +38,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
3838 private currentlyReplacingAttachments = false ;
3939 private switchToEncryptedReply = false ;
4040 private removeNextReplyBoxBorders = false ;
41- private shouldShowEditableSecureReply = false ;
41+ private lastSwitchToEncryptedReply = false ;
4242 private replyOption : ReplyOption | undefined ;
4343
4444 private sel = {
@@ -671,7 +671,6 @@ export class GmailElementReplacer extends WebmailElementReplacer {
671671 replyBox . addClass ( 'reply_message_evaluated' ) ;
672672 continue ;
673673 }
674- this . switchToEncryptedReply = false ;
675674 if ( this . removeNextReplyBoxBorders ) {
676675 replyBox . addClass ( 'remove_borders' ) ;
677676 this . removeNextReplyBoxBorders = false ;
@@ -686,12 +685,17 @@ export class GmailElementReplacer extends WebmailElementReplacer {
686685 const isReplyButtonView = replyBoxEl . className . includes ( 'nr' ) ;
687686 const replyBoxes = document . querySelectorAll ( 'iframe.reply_message' ) ;
688687 const alreadyHasSecureReplyBox = replyBoxes . length > 0 ;
689- this . shouldShowEditableSecureReply = ! isReplyButtonView ;
690688 const secureReplyBoxXssSafe = /* xss-safe-factory */ `
691689 <div class="remove_borders reply_message_iframe_container">
692- ${ this . factory . embeddedReply ( replyParams , this . shouldShowEditableSecureReply || alreadyHasSecureReplyBox ) }
690+ ${ this . factory . embeddedReply ( replyParams , ! isReplyButtonView || alreadyHasSecureReplyBox || this . lastSwitchToEncryptedReply ) }
693691 </div>
694692 ` ;
693+ // Added `lastSwitchToEncryptedReply` logic to handle when a user switches from `plain reply` to `encrypted reply`
694+ // by clicking the `Switch to encrypted reply` button.
695+ // Initially, this action removes the `plain reply view` and replaces it with the `plain reply button view`,
696+ // which previously led to an incorrect status in `switchToEncryptedReply`.
697+ // https://github.com/FlowCrypt/flowcrypt-browser/pull/5778
698+ this . lastSwitchToEncryptedReply = false ;
695699 if ( hasDraft || alreadyHasSecureReplyBox ) {
696700 replyBox . addClass ( 'reply_message_evaluated remove_borders' ) . parent ( ) . append ( secureReplyBoxXssSafe ) ; // xss-safe-factory
697701 replyBox . hide ( ) ;
@@ -700,6 +704,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
700704 this . replyOption = undefined ;
701705 } else {
702706 const deleteReplyEl = document . querySelector ( '.oh.J-Z-I.J-J5-Ji.T-I-ax7' ) ;
707+ this . lastSwitchToEncryptedReply = this . switchToEncryptedReply ;
703708 if ( deleteReplyEl ) {
704709 // Remove standard reply by clicking `delete` button
705710 ( deleteReplyEl as HTMLElement ) . click ( ) ;
@@ -708,6 +713,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
708713 midConvoDraft = true ; // last box was processed first (looping in reverse), and all the rest must be drafts
709714 }
710715 }
716+ this . switchToEncryptedReply = false ;
711717 }
712718 }
713719 } ;
0 commit comments