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: handle second nb merge case correctly
thecodrr9aeb6fe1dd5f
diff --git a/packages/core/__tests__/notebooks.test.js b/packages/core/__tests__/notebooks.test.jsindex b31c2ecbc..fb0903d0f 100644--- a/packages/core/__tests__/notebooks.test.js+++ b/packages/core/__tests__/notebooks.test.js@@ -117,6 +117,8 @@ test("merge notebook with topic removed that is edited in the local notebook", (const newNotebook = { ...notebook.data, remote: true };newNotebook.topics.splice(1, 1); // remove hello topic+ await StorageInterface.write("lastSynced", Date.now());+await delay(500);await notebook.topics.add({diff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.jsindex 14830b8aa..5029ebfb8 100644--- a/packages/core/collections/notebooks.js+++ b/packages/core/collections/notebooks.js@@ -11,8 +11,9 @@ export default class Notebooks extends Collection {let localNotebook = this._collection.getItem(id);if (localNotebook && localNotebook.topics?.length) {- // merge new and old topics+ const lastSyncedTimestamp = await this._db.lastSynced();+ // merge new and old topics// We need to handle 3 cases:for (let oldTopic of localNotebook.topics) {const newTopicIndex = remoteNotebook.topics.findIndex(@@ -21,9 +22,9 @@ export default class Notebooks extends Collection {const newTopic = remoteNotebook.topics[newTopicIndex];// CASE 1: if topic exists in old notebook but not in new notebook, it's deleted.- // However, if the dateEdited of topic in the old notebook is > the dateEdited of newNotebook+ // However, if the dateEdited of topic in the old notebook is > lastSyncedTimestamp// it was newly added or edited so add it to the new notebook.- if (!newTopic && oldTopic.dateEdited > remoteNotebook.dateEdited) {+ if (!newTopic && oldTopic.dateEdited > lastSyncedTimestamp) {remoteNotebook.topics.push(oldTopic);}