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
core: create conflict if local item is unsynced
Abdullah Atta4c4cda1c39e3
diff --git a/packages/core/__e2e__/sync.test.js b/packages/core/__e2e__/sync.test.jsindex 0ff0903c4..1a214bf6f 100644--- a/packages/core/__e2e__/sync.test.js+++ b/packages/core/__e2e__/sync.test.js@@ -222,6 +222,45 @@ test(TEST_TIMEOUT * 10);+test(+ "case 5: remote content changed after local content should create a conflict",+ async (t) => {+ const [deviceA, deviceB] = await Promise.all([+ initializeDevice("deviceA"),+ initializeDevice("deviceB")+ ]);++ t.onTestFinished(async (r) => {+ console.log(`${t.task.name} log out`);+ await cleanup(deviceA, deviceB);+ });++ const noteId = await deviceA.notes.add({+ title: "Test note from device A",+ content: { data: "<p>Hello</p>", type: "tiptap" }+ });+ await deviceA.sync({ type: "full" });+ await deviceB.sync({ type: "full" });++ await deviceA.notes.add({+ id: noteId,+ content: { data: "<p>Hello (I am from device B)</p>", type: "tiptap" }+ });+ await deviceA.sync({ type: "full" });++ await new Promise((resolve) => setTimeout(resolve, 10000));++ await deviceB.notes.add({+ id: noteId,+ content: { data: "<p>Hello (I am from device A)</p>", type: "tiptap" }+ });+ await deviceB.sync({ type: "full" });++ expect(await deviceB.notes.conflicted.count()).toBeGreaterThan(0);+ },+ TEST_TIMEOUT * 10+);+// test(// "case 4: Device A's sync is interrupted halfway and Device B makes some changes afterwards and syncs.",// async () => {diff --git a/packages/core/src/api/sync/merger.ts b/packages/core/src/api/sync/merger.tsindex f7ad19e10..5d655a293 100644--- a/packages/core/src/api/sync/merger.ts+++ b/packages/core/src/api/sync/merger.ts@@ -121,9 +121,8 @@ export function isContentConflicted(remoteItem.dateModified &&localItem.dateResolved === remoteItem.dateModified;const isEdited =- // the local item is edited if it was changed/edited after the remote- // note and it also wasn't synced yet.- localItem.dateEdited > remoteItem.dateEdited && !localItem.synced;+ // the local item is edited if it wasn't synced yet.+ !localItem.synced;if (isEdited && !isResolved) {// If time difference between local item's edits & remote item's edits// is less than threshold, we shouldn't trigger a merge conflict; instead