mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
fix: multiple settings objects created for 1 user
due to these multiple objects reset password wasn't working because only the latest one would be encrypted with the new password but all previous objects would require decryption which resulted in a block while syncing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { EV, EVENTS } from "../common";
|
||||
import id from "../utils/id";
|
||||
import setManipulator from "../utils/set";
|
||||
|
||||
class Settings {
|
||||
/**
|
||||
@@ -8,13 +9,7 @@ class Settings {
|
||||
*/
|
||||
constructor(db) {
|
||||
this._db = db;
|
||||
this._settings = {
|
||||
type: "settings",
|
||||
id: id(),
|
||||
pins: [],
|
||||
dateEdited: 0,
|
||||
dateCreated: Date.now(),
|
||||
};
|
||||
this._settings = undefined;
|
||||
}
|
||||
|
||||
get raw() {
|
||||
@@ -22,23 +17,28 @@ class Settings {
|
||||
}
|
||||
|
||||
async merge(item) {
|
||||
this._settings = {
|
||||
...this._settings,
|
||||
...item,
|
||||
};
|
||||
await this._db.context.write("settings", this._settings);
|
||||
// TODO if (this.settings.dateEdited > (await this._db.lastSynced())) {
|
||||
// this._settings.pins = setManipulator.union(
|
||||
// this._settings.pins,
|
||||
// item.pins
|
||||
// );
|
||||
// }
|
||||
this._settings = item;
|
||||
await this._db.context.write("settings", item);
|
||||
}
|
||||
|
||||
async init() {
|
||||
var settings = await this._db.context.read("settings");
|
||||
if (!settings) await this._db.context.write("settings", this._settings);
|
||||
else this._settings = settings;
|
||||
this._settings = settings;
|
||||
EV.subscribe(EVENTS.userLoggedOut, () => {
|
||||
this._settings = undefined;
|
||||
});
|
||||
EV.subscribe(EVENTS.userSignedUp, () => {
|
||||
this._settings = {
|
||||
type: "settings",
|
||||
id: id(),
|
||||
pins: [],
|
||||
dateEdited: 0,
|
||||
dateEdited: Date.now(),
|
||||
dateCreated: Date.now(),
|
||||
};
|
||||
});
|
||||
@@ -66,6 +66,7 @@ class Settings {
|
||||
}
|
||||
|
||||
get pins() {
|
||||
if (!this._settings) return [];
|
||||
return this._settings.pins.reduce((prev, pin) => {
|
||||
let item;
|
||||
if (pin.type === "notebook") {
|
||||
|
||||
Reference in New Issue
Block a user