From a853bb0661520ec0061a652706c31b6e1d25470b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 14 Dec 2016 14:15:27 +0200 Subject: [PATCH] Fix removed translator handling in connectors --- .../zotero/xpcom/connector/translator.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/connector/translator.js b/chrome/content/zotero/xpcom/connector/translator.js index 1478ed31b0..078af85731 100644 --- a/chrome/content/zotero/xpcom/connector/translator.js +++ b/chrome/content/zotero/xpcom/connector/translator.js @@ -225,22 +225,17 @@ Zotero.Translators = new function() { if(!_initialized) Zotero.Translators.init(); if(!newMetadata.length) return; - if(reset) { - var serializedTranslators = newMetadata.filter(function(translator) { - return !translator.deleted; - }); - } else { + if(!reset) { + var existingTranslatorIDs = new Set(); var serializedTranslators = []; var hasChanged = false; // Update translators with new metadata for(var i in newMetadata) { var newTranslator = newMetadata[i]; + existingTranslatorIDs.add(newTranslator.translatorID); - if(newTranslator.deleted) { - // handle translator deletions - delete _translators[newTranslator.translatorID]; - } else if(_translators.hasOwnProperty(newTranslator.translatorID)) { + if(_translators.hasOwnProperty(newTranslator.translatorID)) { var oldTranslator = _translators[newTranslator.translatorID]; // check whether translator has changed @@ -251,17 +246,26 @@ Zotero.Translators = new function() { continue; } - Zotero.debug("Translators: Updating "+newTranslator.label); + Zotero.debug(`Translators: Updating ${newTranslator.label}`); oldTranslator.init(newTranslator); hasChanged = true; } } else { - Zotero.debug("Translators: Adding "+newTranslator.label); + Zotero.debug(`Translators: Adding ${newTranslator.label}`); _translators[newTranslator.translatorID] = new Zotero.Translator(newTranslator); hasChanged = true; } } + let deletedTranslators = Object.keys(_translators).filter((ID) => !existingTranslatorIDs.has(ID)); + if (deletedTranslators.length) { + hasChanged = true; + for (let ID of deletedTranslators) { + Zotero.debug(`Translators: Removing ${_translators[ID].label}`); + delete _translators[ID]; + } + } + if(!hasChanged) return; // Serialize translators