Trigger auto-sync after item deletion

It looks like this has been broken for years.
This commit is contained in:
Dan Stillman 2021-05-14 03:12:33 -04:00
parent 9a47f74787
commit 5b0f02a12b
2 changed files with 24 additions and 1 deletions

View file

@ -149,9 +149,17 @@ Zotero.Sync.EventListeners.AutoSyncListener = {
else if (Zotero.DataObjectUtilities.getTypes().includes(type)) {
let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type);
ids.forEach(id => {
let libraryID;
let lk = objectsClass.getLibraryAndKeyFromID(id);
if (lk) {
let library = Zotero.Libraries.get(lk.libraryID);
libraryID = lk.libraryID;
}
// On object deletion, libraryID should be in extraData
else if (extraData && extraData[id] && extraData[id].libraryID) {
libraryID = extraData[id].libraryID;
}
if (libraryID) {
let library = Zotero.Libraries.get(libraryID);
if (library.syncable) {
libraries.push(library);
}

View file

@ -97,6 +97,21 @@ describe("Zotero.Sync.EventListeners", function () {
assert.sameMembers(expectation.getCall(0).args[2].libraries, [Zotero.Libraries.userLibraryID]);
});
it("should auto-sync after item deletion", async function () {
Zotero.Prefs.set('sync.autoSync', false);
var item = await createDataObject('item');
Zotero.Prefs.set('sync.autoSync', true);
var mock = sinon.mock(Zotero.Sync.Runner);
var expectation = mock.expects("setSyncTimeout").once();
await item.eraseTx();
await Zotero.Promise.delay(10);
mock.verify();
assert.sameMembers(expectation.getCall(0).args[2].libraries, [Zotero.Libraries.userLibraryID]);
});
it("should auto-sync after attachment reindex", async function () {
Zotero.Prefs.set('sync.autoSync', false);
var attachment = await importFileAttachment('test.pdf');