Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add migrated flag & update dateEdited on migration

thecodrr2b30bd9bf0b2
diff --git a/packages/core/api/sync/collector.js b/packages/core/api/sync/collector.js
index cccef4cbc..7b76e1bf5 100644
--- a/packages/core/api/sync/collector.js
+++ b/packages/core/api/sync/collector.js
@@ -37,10 +37,14 @@ class Collector {
_collect(array) {
return Promise.all(
tfun
- .filter((item) => item.dateEdited > this._lastSyncedTimestamp)
+ .filter(
+ (item) => item.dateEdited > this._lastSyncedTimestamp || item.migrated
+ )
.map(async (item) => {
- // in case of resolved delta, we do not want to send this key to the server
- if (item.resolved) delete item.resolved;
+ // in case of resolved delta
+ item.resolved = false;
+ // turn the migrated flag off so we don't keep syncing this item repeated
+ item.migrated = false;
return {
id: item.id,
diff --git a/packages/core/collections/content.js b/packages/core/collections/content.js
index 6a063bbe9..c70c88c14 100644
--- a/packages/core/collections/content.js
+++ b/packages/core/collections/content.js
@@ -4,7 +4,8 @@ import getId from "../utils/id";
export default class Content extends Collection {
async add(content) {
if (!content) return;
- if (content.deleted) return await this._collection.addItem(content);
+ if (content.deleted || content.migrated)
+ return await this._collection.addItem(content);
if (content.id && (await this._collection.exists(content.id))) {
content = {
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index a84a93fa6..597d29170 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -18,7 +18,7 @@ if (!tfun) {
export default class Notes extends Collection {
async add(noteArg) {
if (!noteArg) return;
- if (noteArg.remote) {
+ if (noteArg.remote || noteArg.migrated) {
return await this._collection.addItem(noteArg);
}
diff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.js
index da909bf7a..38033dcf7 100644
--- a/packages/core/collections/trash.js
+++ b/packages/core/collections/trash.js
@@ -26,7 +26,7 @@ export default class Trash extends Collection {
}
async add(item) {
- if (item.dateDeleted || item.deleted) {
+ if (item.dateDeleted || item.deleted || item.migrated) {
return await this._collection.addItem(item);
}
await this._collection.addItem({
diff --git a/packages/core/migrations.js b/packages/core/migrations.js
index ca147d32f..d61e7df89 100644
--- a/packages/core/migrations.js
+++ b/packages/core/migrations.js
@@ -6,17 +6,20 @@ export const migrations = {
delete item.content;
item.contentId = contentId;
}
- if (item.notebook.id) {
+ if (item.notebook) {
const notebook = item.notebook;
+ delete item.notebook;
item.notebooks = [notebook];
}
- delete item.notebook;
- item.remote = true;
+ item.dateEdited = Date.now();
+ item.migrated = true;
return item;
},
delta: function (item) {
item.data = item.data.ops;
item.type = "delta";
+ item.dateEdited = Date.now();
+ item.migrated = true;
return item;
},
trash: function (item) {
@@ -26,6 +29,8 @@ export const migrations = {
item.contentId = item.content.delta;
delete item.content;
}
+ item.dateEdited = Date.now();
+ item.migrated = true;
return item;
},
},
@@ -34,8 +39,9 @@ export const migrations = {
// notebook -> notebooks
const notebook = item.notebook;
delete item.notebook;
- item.remote = true;
if (notebook) item.notebooks = [notebook];
+ item.dateEdited = Date.now();
+ item.migrated = true;
return item;
},
},