Skip to content

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

fix: colors and tags syncing

thecodrr690cd5186204
diff --git a/packages/core/api/sync/collector.js b/packages/core/api/sync/collector.js
index a0181f334..72f4b418e 100644
--- a/packages/core/api/sync/collector.js
+++ b/packages/core/api/sync/collector.js
@@ -36,8 +36,6 @@ class Collector {
notes: await this._collect(this._db.notes.raw),
notebooks: await this._collect(this._db.notebooks.raw),
content: await this._collect(await this._db.content.all()),
- tags: await this._collect(this._db.tags.raw),
- colors: await this._collect(this._db.colors.raw),
trash: await this._collect(this._db.trash.raw),
settings: await this._collect([this._db.settings.raw]),
vaultKey: await this._serialize(await this._db.vault._getKey()),
diff --git a/packages/core/api/sync/merger.js b/packages/core/api/sync/merger.js
index 565d2cd8c..f651a2eef 100644
--- a/packages/core/api/sync/merger.js
+++ b/packages/core/api/sync/merger.js
@@ -75,8 +75,6 @@ class Merger {
synced,
notebooks,
content,
- tags,
- colors,
trash,
vaultKey,
settings,
@@ -128,17 +126,17 @@ class Merger {
}
);
- await this._mergeArray(
- tags,
- (id) => this._db.tags.tag(id),
- (item) => this._db.tags.merge(item)
- );
-
- await this._mergeArray(
- colors,
- (id) => this._db.colors.tag(id),
- (item) => this._db.colors.merge(item)
- );
+ // await this._mergeArray(
+ // tags,
+ // (id) => this._db.tags.tag(id),
+ // (item) => this._db.tags.merge(item)
+ // );
+
+ // await this._mergeArray(
+ // colors,
+ // (id) => this._db.colors.tag(id),
+ // (item) => this._db.colors.merge(item)
+ // );
await this._mergeArray(
trash,
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index 447c9100d..6a4b16875 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -19,13 +19,35 @@ if (!tfun) {
export default class Notes extends Collection {
async add(noteArg) {
if (!noteArg) return;
- if (noteArg.remote || noteArg.migrated) {
- return await this._collection.addItem(noteArg);
- }
let id = noteArg.id || getId();
let oldNote = this._collection.getItem(id);
+ if (noteArg.remote || noteArg.migrated) {
+ if (oldNote) {
+ if (oldNote.color !== noteArg.color) {
+ await this._db.colors.remove(oldNote.color, id);
+ }
+ if (oldNote.tags) {
+ for (let tag of oldNote.tags) {
+ await this._db.tags.remove(tag, id);
+ }
+ }
+ }
+
+ if (noteArg.color) {
+ await this._db.colors.add(noteArg.color, id);
+ }
+
+ if (noteArg.tags.length) {
+ for (let tag of noteArg.tags) {
+ await this._db.tags.add(tag, id);
+ }
+ }
+
+ return await this._collection.addItem(noteArg);
+ }
+
let note = {
...oldNote,
...noteArg,
diff --git a/packages/core/collections/tags.js b/packages/core/collections/tags.js
index 360ca8fd9..a80d12209 100644
--- a/packages/core/collections/tags.js
+++ b/packages/core/collections/tags.js
@@ -19,6 +19,7 @@ export default class Tags extends Collection {
const oldTag = this.all.find(
(t) => t.id === tag.id || t.title === tag.title
);
+
if (!oldTag) return await this._collection.addItem(tag);
const deletedIds = set.union(oldTag.deletedIds, tag.deletedIds);