replying to the right message. fixes #71
This commit is contained in:
parent
2e6fa9f86a
commit
639fe495a7
2 changed files with 25 additions and 13 deletions
|
|
@ -119,7 +119,7 @@ function chatpgt_scrollToBottom () {
|
||||||
catch (err) { console.error('[ThunderAI] ', err); }
|
catch (err) { console.error('[ThunderAI] ', err); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCustomDiv(prompt_action,tabId) {
|
function addCustomDiv(prompt_action,tabId,mailMessageId) {
|
||||||
// Create <style> element for the CSS
|
// Create <style> element for the CSS
|
||||||
var style = document.createElement('style');
|
var style = document.createElement('style');
|
||||||
style.textContent = ".mzta-header-fixed {position: fixed;bottom: 0;left: 0;height:100px;width: 100%;background-color: #333;color: white;text-align: center;padding: 10px 0;z-index: 1000;border-top: 3px solid white;}"
|
style.textContent = ".mzta-header-fixed {position: fixed;bottom: 0;left: 0;height:100px;width: 100%;background-color: #333;color: white;text-align: center;padding: 10px 0;z-index: 1000;border-top: 3px solid white;}"
|
||||||
|
|
@ -205,7 +205,7 @@ function addCustomDiv(prompt_action,tabId) {
|
||||||
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer");
|
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer");
|
||||||
btn_ok.onclick = async function() {
|
btn_ok.onclick = async function() {
|
||||||
const response = await chatgpt_getFromDOM('last');
|
const response = await chatgpt_getFromDOM('last');
|
||||||
browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: response, tabId: tabId});
|
browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: response, tabId: tabId, mailMessageId: mailMessageId});
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
browser.runtime.sendMessage({command: "chatgpt_close"});
|
browser.runtime.sendMessage({command: "chatgpt_close"});
|
||||||
};
|
};
|
||||||
|
|
@ -215,7 +215,7 @@ function addCustomDiv(prompt_action,tabId) {
|
||||||
btn_ok.onclick = async function() {
|
btn_ok.onclick = async function() {
|
||||||
const response = await chatgpt_getFromDOM('last');
|
const response = await chatgpt_getFromDOM('last');
|
||||||
//console.log('replace text: '+tabId)
|
//console.log('replace text: '+tabId)
|
||||||
browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: response, tabId: tabId});
|
browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: response, tabId: tabId, mailMessageId: mailMessageId});
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
browser.runtime.sendMessage({command: "chatgpt_close"});
|
browser.runtime.sendMessage({command: "chatgpt_close"});
|
||||||
};
|
};
|
||||||
|
|
@ -344,7 +344,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
// User not logged in
|
// User not logged in
|
||||||
alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
|
alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
|
||||||
}else{
|
}else{
|
||||||
addCustomDiv(message.action,message.tabId);
|
addCustomDiv(message.action,message.tabId,message.mailMessageId);
|
||||||
(async () => {
|
(async () => {
|
||||||
if(mztaDoCustomText === 1){
|
if(mztaDoCustomText === 1){
|
||||||
current_message = message;
|
current_message = message;
|
||||||
|
|
|
||||||
|
|
@ -76,14 +76,22 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) =>
|
||||||
replyType = 'replyToSender';
|
replyType = 'replyToSender';
|
||||||
}
|
}
|
||||||
//console.log('replyType: ' + replyType);
|
//console.log('replyType: ' + replyType);
|
||||||
browser.messageDisplay.getDisplayedMessage(message.tabId).then(async (mailMessage) => {
|
// browser.messageDisplay.getDisplayedMessage(message.tabId).then(async (mailMessage) => {
|
||||||
let reply_tab = await browser.compose.beginReply(mailMessage.id, replyType, {
|
// let reply_tab = await browser.compose.beginReply(mailMessage.id, replyType, {
|
||||||
type: "reply",
|
// type: "reply",
|
||||||
//body: paragraphsHtmlString,
|
// //body: paragraphsHtmlString,
|
||||||
isPlainText: false,
|
// isPlainText: false,
|
||||||
identityId: await getCurrentIdentity(mailMessage),
|
// identityId: await getCurrentIdentity(mailMessage),
|
||||||
})
|
// })
|
||||||
|
//console.log(">>>>>>>>>>>> message.mailMessageId: " + message.mailMessageId);
|
||||||
|
browser.messages.get(message.mailMessageId).then(async (mailMessage) => {
|
||||||
|
let curr_idn = await getCurrentIdentity(mailMessage)
|
||||||
|
let reply_tab = await browser.compose.beginReply(mailMessage.id, replyType, {
|
||||||
|
type: "reply",
|
||||||
|
//body: paragraphsHtmlString,
|
||||||
|
isPlainText: false,
|
||||||
|
identityId: curr_idn,
|
||||||
|
})
|
||||||
// Wait for tab loaded.
|
// Wait for tab loaded.
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
const tabIsLoaded = tab => {
|
const tabIsLoaded = tab => {
|
||||||
|
|
@ -92,6 +100,7 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) =>
|
||||||
const listener = (tabId, changeInfo, updatedTab) => {
|
const listener = (tabId, changeInfo, updatedTab) => {
|
||||||
if (tabIsLoaded(updatedTab)) {
|
if (tabIsLoaded(updatedTab)) {
|
||||||
browser.tabs.onUpdated.removeListener(listener);
|
browser.tabs.onUpdated.removeListener(listener);
|
||||||
|
console.log(">>>>>>>>>>>> reply_tab: " + tabId);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +183,10 @@ async function openChatGPT(promptText, action, curr_tabId, do_custom_text = 0) {
|
||||||
browser.tabs.executeScript(createdTab.id, { code: pre_script + mzta_script, matchAboutBlank: false })
|
browser.tabs.executeScript(createdTab.id, { code: pre_script + mzta_script, matchAboutBlank: false })
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
console.log("[ThunderAI] Script injected successfully");
|
console.log("[ThunderAI] Script injected successfully");
|
||||||
browser.tabs.sendMessage(createdTab.id, { command: "chatgpt_send", prompt: promptText, action: action, tabId: curr_tabId });
|
let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId);
|
||||||
|
let mailMessageId = -1;
|
||||||
|
if(mailMessage) mailMessageId = mailMessage.id;
|
||||||
|
browser.tabs.sendMessage(createdTab.id, { command: "chatgpt_send", prompt: promptText, action: action, tabId: curr_tabId, mailMessageId: mailMessageId});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error("[ThunderAI] Error injecting the script: ", err);
|
console.error("[ThunderAI] Error injecting the script: ", err);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue