Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martgil committed Nov 27, 2024
1 parent aa27485 commit 32d4efc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class WebmailElementReplacer {
private replacePgpElsInterval: number;

public abstract getIntervalFunctions: () => IntervalFunction[];
public abstract setReplyBoxEditable: () => Promise<void>;
public abstract setReplyBoxEditable: (messageContainer?: JQuery<Element>) => Promise<void>;
public abstract reinsertReplyBox: (replyMsgId: string) => void;
public abstract scrollToReplyBox: (replyMsgId: string) => void;
public abstract scrollToCursorInReplyBox: (replyMsgId: string, cursorOffsetTop: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ export class GmailElementReplacer extends WebmailElementReplacer {
];
};

public setReplyBoxEditable = async () => {
public setReplyBoxEditable = async (messageContainer?: JQuery<Element>) => {
const replyContainerIframe = $('.reply_message_iframe_container > iframe').last();
if (replyContainerIframe.length) {
$(replyContainerIframe).replaceWith(this.factory.embeddedReply(this.getLastMsgReplyParams(this.getConvoRootEl(replyContainerIframe[0])), true)); // xss-safe-value
if (replyContainerIframe.length && messageContainer) {
$(replyContainerIframe).replaceWith(this.factory.embeddedReply(this.getLastMsgReplyParams(messageContainer), true)); // xss-safe-value
} else {
await this.replaceStandardReplyBox(undefined, true);
}
};

public reinsertReplyBox = (replyMsgId: string) => {
console.log('wew', replyMsgId);
const params: FactoryReplyParams = { replyMsgId };
$('.reply_message_iframe_container:visible')
.last()
Expand Down Expand Up @@ -351,10 +352,10 @@ export class GmailElementReplacer extends WebmailElementReplacer {
return;
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const messageContainer = $(btn.closest('.h7')!);
const messageContainer: JQuery<Element> = $(btn.closest('.h7')!);
if (messageContainer.is(':last-child')) {
if (this.isEncrypted()) {
await this.setReplyBoxEditable();
await this.setReplyBoxEditable(messageContainer);
} else {
await this.replaceStandardReplyBox(undefined, true);
}
Expand Down Expand Up @@ -589,8 +590,10 @@ export class GmailElementReplacer extends WebmailElementReplacer {
return from ? Str.parseEmail(from) : undefined;
};

private getLastMsgReplyParams = (convoRootEl: JQuery): FactoryReplyParams => {
return { replyMsgId: this.determineMsgId($(convoRootEl).find(this.sel.msgInner).last()) };
private getLastMsgReplyParams = (convoRootEl: JQuery<Element>): FactoryReplyParams => {
const msgIdElement = $(convoRootEl).find('[data-legacy-message-id], [data-message-id]');
const msgId = msgIdElement.attr('data-legacy-message-id') || msgIdElement.attr('data-message-id');
return { replyMsgId: msgId };
};

private getConvoRootEl = (anyInnerElement: HTMLElement) => {
Expand Down Expand Up @@ -618,6 +621,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
const convoRootEl = this.getConvoRootEl(newReplyBoxes[0]);
const replyParams = this.getLastMsgReplyParams(convoRootEl);
if (msgId) {
console.log(msgId);
replyParams.replyMsgId = msgId;
}
const hasDraft = newReplyBoxes.filter(replyBox => {
Expand Down Expand Up @@ -665,6 +669,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
const isReplyButtonView = replyBoxEl.className.includes('nr');
const replyBoxes = document.querySelectorAll('iframe.reply_message');
const alreadyHasSecureReplyBox = replyBoxes.length > 0;
console.log('wew', replyParams);
const secureReplyBoxXssSafe = /* xss-safe-factory */ `
<div class="remove_borders reply_message_iframe_container">
${this.factory.embeddedReply(replyParams, !isReplyButtonView || alreadyHasSecureReplyBox || this.lastSwitchToEncryptedReply)}
Expand Down

0 comments on commit 32d4efc

Please sign in to comment.