Skip to content

Commit

Permalink
Additional comments and cleanup for target selector handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Mar 29, 2018
1 parent 9b9773d commit c5cd38b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions chrome/content/zotero/xpcom/server_connector.js
Expand Up @@ -81,7 +81,7 @@ Zotero.Server.Connector.SessionManager = {
},

create: function (id) {
// Legacy client
// Legacy connector
if (!id) {
Zotero.debug("No session id provided by client", 2);
id = Zotero.Utilities.randomString();
Expand Down Expand Up @@ -124,6 +124,9 @@ Zotero.Server.Connector.SaveSession.prototype.addItems = async function (items)
return this._addObjects('item', items);
};

/**
* Change the target data for this session and update any items that have already been saved
*/
Zotero.Server.Connector.SaveSession.prototype.update = async function (libraryID, collectionID, tags) {
this._currentLibraryID = libraryID;
this._currentCollectionID = collectionID;
Expand Down Expand Up @@ -161,20 +164,22 @@ Zotero.Server.Connector.SaveSession.prototype.update = async function (libraryID
};

Zotero.Server.Connector.SaveSession.prototype._addObjects = async function (objectType, objects) {
if (!this._objects[objectType]) {
this._objects[objectType] = new Set();
}

// If target has changed since the save began, update the objects
// Update the objects with the current target data, in case it changed since the save began
await this._updateObjects({
[objectType]: objects
});

if (!this._objects[objectType]) {
this._objects[objectType] = new Set();
}
for (let object of objects) {
this._objects[objectType].add(object);
}
};

/**
* Update the passed objects with the current target and tags
*/
Zotero.Server.Connector.SaveSession.prototype._updateObjects = async function (objects) {
if (Object.keys(objects).every(type => objects[type].length == 0)) {
return;
Expand All @@ -190,8 +195,6 @@ Zotero.Server.Connector.SaveSession.prototype._updateObjects = async function (o
return Zotero.DB.executeTransaction(async function () {
for (let objectType in objects) {
for (let object of objects[objectType]) {
Zotero.debug(object.libraryID);
Zotero.debug(libraryID);
if (object.libraryID != libraryID) {
throw new Error("Can't move objects between libraries");
}
Expand Down

0 comments on commit c5cd38b

Please sign in to comment.