diff --git a/js/mzta-utils.js b/js/mzta-utils.js index 366cce44..b044d2db 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -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); } diff --git a/mzta-background.js b/mzta-background.js index 2513ae37..df5dee37 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -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) => {