Skip to content

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

fix: tag/color aliases not syncing

thecodrra2bab0940d2e
diff --git a/packages/core/api/settings.js b/packages/core/api/settings.js
index bbe001698..aa9ff7eb9 100644
--- a/packages/core/api/settings.js
+++ b/packages/core/api/settings.js
@@ -31,17 +31,21 @@ class Settings {
if (this._settings.dateEdited > (await this._db.lastSynced())) {
this._settings.pins = setManipulator.union(
this._settings.pins,
- item.pins
+ item.pins,
+ (p) => p.data.id
);
this._settings.groupOptions = {
- ...item.groupOptions,
...this._settings.groupOptions,
+ ...item.groupOptions,
+ };
+ this._settings.aliases = {
+ ...this._settings.aliases,
+ ...item.aliases,
};
- this._settings.aliases = {};
} else {
this._initSettings(item);
}
- await this._saveSettings();
+ await this._saveSettings(false);
}
/**
@@ -137,8 +141,8 @@ class Settings {
};
}
- async _saveSettings() {
- this._settings.dateEdited = Date.now();
+ async _saveSettings(updateDateEdited = true) {
+ if (updateDateEdited) this._settings.dateEdited = Date.now();
await this._db.storage.write("settings", this._settings);
}
}
diff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.js
index de5e76e11..7abd3ff7e 100644
--- a/packages/core/collections/notebooks.js
+++ b/packages/core/collections/notebooks.js
@@ -41,7 +41,11 @@ export default class Notebooks extends Collection {
else if (newTopic && oldTopic.dateEdited > newTopic.dateEdited) {
remoteNotebook.topics[newTopicIndex] = {
...oldTopic,
- notes: setManipulator.union(oldTopic.notes, newTopic.notes),
+ notes: setManipulator.union(
+ oldTopic.notes,
+ newTopic.notes,
+ (n) => n.id
+ ),
dateEdited: Date.now(),
};
}
diff --git a/packages/core/utils/set.js b/packages/core/utils/set.js
index df8541ce4..5e71fb781 100644
--- a/packages/core/utils/set.js
+++ b/packages/core/utils/set.js
@@ -3,19 +3,14 @@
// Set operations union, intersection, symmetric difference,
// relative complement, equals. Set operations are fast.
-class SetManipulator {
- constructor() {
- // Create and push the uid identity method.
- let identityExtractor = (identity) => identity;
- this.uidList = [identityExtractor];
- this.uid = identityExtractor;
- }
+export class SetManipulator {
+ constructor() {}
// Processes a histogram consructed from two arrays, 'a' and 'b'.
// This function is used generically by the below set operation
// methods, a.k.a, 'evaluators', to return some subset of
// a set union, based on frequencies in the histogram.
- process(a, b, evaluator) {
+ process(a, b, getKey = (k) => k, evaluator) {
// If identity extractor passed in, push it on the stack
//if (identityExtractor) this.pushIdentityExtractor(identityExtractor);
// Create a histogram of 'a'.
@@ -23,14 +18,14 @@ class SetManipulator {
const out = [];
let ukey;
a.forEach((value) => {
- ukey = this.uid(value);
+ ukey = getKey(value);
if (!hist[ukey]) {
hist[ukey] = { value: value, freq: 1 };
}
});
// Merge 'b' into the histogram.
b.forEach((value) => {
- ukey = this.uid(value);
+ ukey = getKey(value);
if (hist[ukey]) {
if (hist[ukey].freq === 1) hist[ukey].freq = 3;
} else hist[ukey] = { value: value, freq: 2 };
@@ -50,8 +45,8 @@ class SetManipulator {
// Join two sets together.
// Set.union([1, 2, 2], [2, 3]) => [1, 2, 3]
- union(a, b) {
- return this.process(a, b, () => true);
+ union(a, b, getKey) {
+ return this.process(a, b, getKey, () => true);
}
// Return items common to both sets.