Enhance tag assignment logging and prevent new tag creation when not needed. see #390

This commit is contained in:
mic 2025-05-25 22:03:08 +02:00
parent ea22caa23c
commit bbf8eb7c5e
2 changed files with 13 additions and 9 deletions

View file

@ -357,8 +357,8 @@ export async function createTag(tag) {
// }
export function checkIfTagLabelExists(tag_label, tags_list) {
console.log(">>>>>>>>>>> checkIfTagExists tags_list: " + JSON.stringify(tags_list));
console.log(">>>>>>>>>>> checkIfTagExists tag_label: " + tag_label);
// console.log(">>>>>>>>>>> checkIfTagExists tags_list: " + JSON.stringify(tags_list));
// console.log(">>>>>>>>>>> checkIfTagExists tag_label: " + tag_label);
const lowerTagLabel = tag_label.toLowerCase();
return Object.values(tags_list).some(label => label.tag.toLowerCase() === lowerTagLabel);
}
@ -376,18 +376,19 @@ export function checkIfTagLabelExists(tag_label, tags_list) {
// }
export async function assignTagsToMessage(messageId, tags) {
console.log(">>>>>>>>>>> assignTagsToMessage tags: " + JSON.stringify(tags));
// console.log(">>>>>>>>>>> assignTagsToMessage tags: " + JSON.stringify(tags));
let all_tags_list = await getTagsList();
all_tags_list = all_tags_list[1];
tags = getTagsKeyFromLabel(tags, all_tags_list);
console.log(">>>>>>>>>>> assignTagsToMessage tags after conversion: " + JSON.stringify(tags));
// console.log(">>>>>>>>>>> assignTagsToMessage tags after conversion: " + JSON.stringify(tags));
let msg_prop = await browser.messages.get(messageId);
console.log(">>>>>>>>>>> assignTagsToMessage msg_prop.tags: " + JSON.stringify(msg_prop.tags));
// console.log(">>>>>>>>>>> assignTagsToMessage msg_prop.tags: " + JSON.stringify(msg_prop.tags));
tags = tags.concat(msg_prop.tags || []);
tags = [...new Set(tags)];
console.log(">>>>>>>>>>> assignTagsToMessage tags after concat: " + JSON.stringify(tags));
// console.log(">>>>>>>>>>> assignTagsToMessage tags after concat: " + JSON.stringify(tags));
try {
return browser.messages.update(messageId, {tags: tags});
await browser.messages.update(messageId, {tags: tags});
return tags; // Return the updated tags for confirmation
} catch (error) {
console.error('[ThunderAI] Error assigning tag [messageId: ', messageId, ' - tag: ', tag, ']:', error);
}

View file

@ -160,6 +160,9 @@ async function _assign_tags(_data, create_new_tags = true) {
// console.log(">>>>>>>>>>>>>>> all_tags_list: " + JSON.stringify(all_tags_list));
taLog.log("assign_tags data: " + JSON.stringify(_data));
let new_tags = [];
if(!create_new_tags){
taLog.log("Not creating new tags, only assigning existing ones...");
}
for (const tag of _data.tags) {
// console.log(">>>>>>>>>>>>>>> tag: " + JSON.stringify(tag));
if (create_new_tags && !checkIfTagLabelExists(tag, all_tags_list)) {
@ -168,8 +171,8 @@ async function _assign_tags(_data, create_new_tags = true) {
}
new_tags.push(tag);
}
await assignTagsToMessage(_data.messageId, new_tags);
taLog.log("Assigned tags: " + JSON.stringify(new_tags));
let added_tags = await assignTagsToMessage(_data.messageId, new_tags);
taLog.log("Assigned tags: " + JSON.stringify(added_tags));
}
messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {