From e6ce021b5f49fbe5e6203d04c568cceb39f94b9e Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Thu, 12 Jun 2025 12:01:23 -0700 Subject: [PATCH] return tags in /connector/getSelectedCollection Together with all collections and libraries. To account for tags that may contain "," characters, expect connector to send tags as an array. If tags are sent as a string, it will be split by "," for compatibility with older connector versions. Addresses: #1706 --- chrome/content/zotero/xpcom/server/saveSession.js | 5 ++--- .../content/zotero/xpcom/server/server_connector.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/server/saveSession.js b/chrome/content/zotero/xpcom/server/saveSession.js index 81508a1cc2..54aff5e402 100644 --- a/chrome/content/zotero/xpcom/server/saveSession.js +++ b/chrome/content/zotero/xpcom/server/saveSession.js @@ -169,7 +169,7 @@ Zotero.Server.Connector.SaveSession = class { async update(targetID, tags, note) { var previousTargetID = this._currentTargetID; this._currentTargetID = targetID; - this._currentTags = tags || ""; + this._currentTags = tags || []; this._currentNote = note || ""; // Select new destination in collections pane @@ -206,8 +206,7 @@ Zotero.Server.Connector.SaveSession = class { var { library, collection } = Zotero.Server.Connector.resolveTarget(this._currentTargetID); var libraryID = library.libraryID; - var tags = this._currentTags.trim(); - tags = tags ? tags.split(/\s*,\s*/).filter(x => x) : []; + var tags = this._currentTags.map(tag => tag.trim()).filter(tag => tag); Zotero.debug("Updating items for connector save session " + this.id); diff --git a/chrome/content/zotero/xpcom/server/server_connector.js b/chrome/content/zotero/xpcom/server/server_connector.js index 32a4bf57ca..50e53214ef 100644 --- a/chrome/content/zotero/xpcom/server/server_connector.js +++ b/chrome/content/zotero/xpcom/server/server_connector.js @@ -760,6 +760,11 @@ Zotero.Server.Connector.UpdateSession.prototype = { // Parse treeViewID var [type, id] = [data.target[0], parseInt(data.target.substr(1))]; var tags = data.tags; + // Older connector versions send tags as one string with comma as delimiter + // To account for tags that contain commas, later versions send an array of strings + if (typeof tags === 'string') { + tags = tags.split(","); + } var note = data.note; if (type == 'C') { @@ -931,7 +936,7 @@ Zotero.Server.Connector.GetSelectedCollection.prototype = { * @param {String} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - init: function(postData, sendResponseCallback) { + init: async function(postData, sendResponseCallback) { let allowReadOnly = (postData.hasOwnProperty("switchToReadableLibrary")) ? !postData.switchToReadableLibrary : true; var { library, collection, editable } = Zotero.Server.Connector.getSaveTarget(allowReadOnly); var response = { @@ -950,12 +955,14 @@ Zotero.Server.Connector.GetSelectedCollection.prototype = { response.name = response.libraryName; } - // Get list of editable libraries and collections + // Get list of editable libraries, collections, and tags var collections = []; + let tags = {}; var originalLibraryID = library.libraryID; for (let library of Zotero.Libraries.getAll()) { if (!library.editable) continue; + tags[library.treeViewID] = await Zotero.Tags.getAll(library.libraryID); // Add recent: true for recent targets collections.push( @@ -974,6 +981,7 @@ Zotero.Server.Connector.GetSelectedCollection.prototype = { ); } response.targets = collections; + response.tags = tags; // Mark recent targets try { @@ -1105,6 +1113,7 @@ Zotero.Server.Connector.Ping.prototype = { automaticSnapshots: Zotero.Prefs.get('automaticSnapshots'), downloadAssociatedFiles: Zotero.Prefs.get("downloadAssociatedFiles"), supportsAttachmentUpload: true, + supportsTagsAutocomplete: true, googleDocsAddNoteEnabled: true, canUserAddNote: true, googleDocsCitationExplorerEnabled: false,