A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: remove notebook reference from notes that are removed from topic during merge
thecodrr61e608b2dcc1
diff --git a/packages/core/api/sync/__tests__/sync.test.js b/packages/core/api/sync/__tests__/sync.test.jsindex fab27cda9..33f36e6b9 100644--- a/packages/core/api/sync/__tests__/sync.test.js+++ b/packages/core/api/sync/__tests__/sync.test.js@@ -260,7 +260,7 @@ test.skip();test.skip(- "issue: new topics on 2 devices are not properly synced",+ "issue: new topic on device A gets replaced by the new topic on device B",async () => {const deviceA = await initializeDevice("deviceA");const deviceB = await initializeDevice("deviceB");@@ -299,6 +299,53 @@ test.skip(60 * 1000);+test.skip(+ "issue: remove notebook reference from notes that are removed from topic during merge",+ async () => {+ const deviceA = await initializeDevice("deviceA");+ const deviceB = await initializeDevice("deviceB");++ const id = await deviceA.notebooks.add({+ title: "Notebook 1",+ topics: ["Topic 1"],+ });++ await syncAndWait(deviceA, deviceB, false);++ expect(deviceB.notebooks.notebook(id)).toBeDefined();++ const noteA = await deviceA.notes.add({ title: "Note 1" });+ await deviceA.notes.move({ id, topic: "Topic 1" }, noteA);++ expect(+ deviceA.notebooks.notebook(id).topics.topic("Topic 1").totalNotes+ ).toBe(1);++ await delay(2000);++ const noteB = await deviceB.notes.add({ title: "Note 2" });+ await deviceB.notes.move({ id, topic: "Topic 1" }, noteB);++ expect(+ deviceB.notebooks.notebook(id).topics.topic("Topic 1").totalNotes+ ).toBe(1);++ await syncAndWait(deviceB, deviceA, false);++ expect(+ deviceA.notebooks.notebook(id).topics.topic("Topic 1").totalNotes+ ).toBe(1);+ expect(+ deviceB.notebooks.notebook(id).topics.topic("Topic 1").totalNotes+ ).toBe(1);++ expect(deviceA.notes.note(noteA).data.notebooks).toHaveLength(0);++ await cleanup(deviceA, deviceB);+ },+ 60 * 1000+);+/**** @param {string} iddiff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.jsindex 8a701eb44..b1472037e 100644--- a/packages/core/collections/notebooks.js+++ b/packages/core/collections/notebooks.js@@ -46,6 +46,20 @@ export default class Notebooks extends Collection {};isChanged = true;}+ // CASE 4: if topic exists in both notebooks:+ // if newTopic.dateEdited > oldTopic.dateEdited: we iterate+ // on all notes that are not in newTopic (if any)+ // and dereference them.+ else if (newTopic && newTopic.dateEdited > oldTopic.dateEdited) {+ const removedNotes = setManipulator.complement(+ oldTopic.notes,+ newTopic.notes+ );++ await this.notebook(remoteNotebook.id)+ .topics.topic(oldTopic.id)+ .delete(...removedNotes);+ }}remoteNotebook.remote = !isChanged;}