From 73ba5f9ffe752b7917435ac215e573f329d56291 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 20 Feb 2021 04:25:28 -0500 Subject: [PATCH] Auto-sync after setting change --- .../zotero/xpcom/sync/syncEventListeners.js | 33 ++++++++++++++----- test/tests/syncEventListenersTest.js | 14 ++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync/syncEventListeners.js b/chrome/content/zotero/xpcom/sync/syncEventListeners.js index d06b316ed4..01d0ace97f 100644 --- a/chrome/content/zotero/xpcom/sync/syncEventListeners.js +++ b/chrome/content/zotero/xpcom/sync/syncEventListeners.js @@ -124,24 +124,39 @@ Zotero.Sync.EventListeners.AutoSyncListener = { } // Only trigger sync for certain types - // - // TODO: settings, full text - if (!Zotero.DataObjectUtilities.getTypes().includes(type)) { + // TODO: full text + if (![...Zotero.DataObjectUtilities.getTypes(), 'setting'].includes(type)) { return; } // Determine affected libraries so only those can be synced let libraries = []; - let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type); - ids.forEach(id => { - let lk = objectsClass.getLibraryAndKeyFromID(id); - if (lk) { - let library = Zotero.Libraries.get(lk.libraryID); + + if (type == 'setting') { + for (let id of ids) { + // E.g., '1/lastPageIndex_u_ABCD2345' + let libraryID = parseInt(id.split('/')[0]); + let library = Zotero.Libraries.get(libraryID); if (library.syncable) { libraries.push(library); } } - }); + } + else if (Zotero.DataObjectUtilities.getTypes().includes(type)) { + let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type); + ids.forEach(id => { + let lk = objectsClass.getLibraryAndKeyFromID(id); + if (lk) { + let library = Zotero.Libraries.get(lk.libraryID); + if (library.syncable) { + libraries.push(library); + } + } + }); + } + else { + return; + } libraries = Zotero.Sync.Data.Local.filterSkippedLibraries(libraries); if (!libraries.length) { diff --git a/test/tests/syncEventListenersTest.js b/test/tests/syncEventListenersTest.js index 2520d51dcd..d2b4666617 100644 --- a/test/tests/syncEventListenersTest.js +++ b/test/tests/syncEventListenersTest.js @@ -77,5 +77,19 @@ describe("Zotero.Sync.EventListeners", function () { yield Zotero.Promise.delay(10); mock.verify(); }); + + it("should auto-sync after settings change", async function () { + var attachment = await importFileAttachment('test.pdf'); + + var mock = sinon.mock(Zotero.Sync.Runner); + var expectation = mock.expects("setSyncTimeout").once(); + + // Create setting (e.g., lastPageIndex_u_ABCD2345) + await attachment.setAttachmentLastPageIndex(1); + + await Zotero.Promise.delay(10); + mock.verify(); + assert.sameMembers(expectation.getCall(0).args[2].libraries, [Zotero.Libraries.userLibraryID]); + }); }); });