correctly assigning multiple tags. see #183

This commit is contained in:
Mic 2024-12-18 01:23:00 +01:00
parent 1b741283d8
commit 4bab16adbc
3 changed files with 14 additions and 9 deletions

View file

@ -218,7 +218,7 @@ export class mzta_Menus {
this.logger.log("fullPrompt: " + fullPrompt);
// TODO: use the current API, abort if using chatgpt web
// COMMENTED TO DO TESTS
mail_tags = "recipients, test, home, work, CAR, light";
mail_tags = "recipients, TEST, home, work, CAR, light";
// let cmd_addTags = new mzta_specialCommand_AddTags(fullPrompt,prefs_at.connection_type,true);
// await cmd_addTags.initWorker();
// try{

View file

@ -212,9 +212,12 @@ export async function createTag(tag) {
}
}
export async function assignTagToMessage(messageId, tag) {
export async function assignTagsToMessage(messageId, tags) {
tags = tags.map(tag => `ta-${tag.toLowerCase()}`);
let msg_prop = await browser.messages.get(messageId);
tags = tags.concat(msg_prop.tags || []);
try {
return browser.messages.update(messageId, {tags: ["ta-"+tag.toLowerCase()]});
return browser.messages.update(messageId, {tags: tags});
} catch (error) {
console.error('[ThunderAI] Error assigning tag [messageId: ', messageId, ' - tag: ', tag, ']:', error);
}

View file

@ -20,7 +20,7 @@ import { mzta_script } from './js/mzta-chatgpt.js';
import { prefs_default } from './options/mzta-options-default.js';
import { mzta_Menus } from './js/mzta-menus.js';
import { taLogger } from './js/mzta-logger.js';
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagToMessage } from './js/mzta-utils.js';
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage } from './js/mzta-utils.js';
await migrateCustomPromptsStorage();
await migrateDefaultPromptsPropStorage();
@ -238,15 +238,17 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
all_tags_list = all_tags_list[1];
console.log(">>>>>>>>>>>>>>> all_tags_list: " + JSON.stringify(all_tags_list));
taLog.log("assign_tags data: " + JSON.stringify(message));
message.tags.forEach(async (tag) => {
let new_tags = [];
for (const tag of message.tags) {
console.log(">>>>>>>>>>>>>>> tag: " + tag);
if (!all_tags_list.hasOwnProperty("ta-"+tag)) {
if (!all_tags_list.hasOwnProperty("ta-" + tag.toLowerCase())) {
taLog.log("Creating tag: " + tag);
await createTag(tag);
}
await assignTagToMessage(message.messageId, tag);
taLog.log("Assigned tag: " + tag);
});
new_tags.push(tag);
}
await assignTagsToMessage(message.messageId, new_tags);
taLog.log("Assigned tags: " + JSON.stringify(new_tags));
}
return _assign_tags();
break;