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
feat: auto create session history on content edit
thecodrr9a984df1bd3d
diff --git a/packages/core/api/vault.js b/packages/core/api/vault.jsindex 3a4e3d3e7..cb2230f59 100644--- a/packages/core/api/vault.js+++ b/packages/core/api/vault.js@@ -179,13 +179,18 @@ export default class Vault {}/** @private */- async _encryptContent(contentId, content, type, password) {+ async _encryptContent(contentId, sessionId, content, type, password) {let encryptedContent = await this._storage.encrypt({ password },JSON.stringify(content));- await this._db.content.add({ id: contentId, data: encryptedContent, type });+ await this._db.content.add({+ id: contentId,+ sessionId,+ data: encryptedContent,+ type,+ });}/** @private */@@ -202,7 +207,7 @@ export default class Vault {/** @private */async _lockNote(note, password) {- let { id, content: { type, data } = {}, contentId } = note;+ let { id, content: { type, data } = {}, contentId, sessionId } = note;// Case: when note is being newly lockedif (!data || !type || !contentId) {@@ -225,7 +230,7 @@ export default class Vault {type = content.type;}- await this._encryptContent(contentId, data, type, password);+ await this._encryptContent(contentId, sessionId, data, type, password);return await this._db.notes.add({id,diff --git a/packages/core/collections/content.js b/packages/core/collections/content.jsindex bb95e79f7..7b3cd9dbb 100644--- a/packages/core/collections/content.js+++ b/packages/core/collections/content.js@@ -21,20 +21,27 @@ export default class Content extends Collection {}const id = content.id || getId();- await this._collection.addItem(- await this.extractAttachments({- noteId: content.noteId,- id,- type: content.type,- data: content.data || content,- dateEdited: content.dateEdited,- dateCreated: content.dateCreated,- dateModified: content.dateModified,- localOnly: !!content.localOnly,- conflicted: content.conflicted,- dateResolved: content.dateResolved,- })- );++ const contentItem = await this.extractAttachments({+ noteId: content.noteId,+ id,+ type: content.type,+ data: content.data || content,+ dateEdited: content.dateEdited,+ dateCreated: content.dateCreated,+ dateModified: content.dateModified,+ localOnly: !!content.localOnly,+ conflicted: content.conflicted,+ dateResolved: content.dateResolved,+ });+ await this._collection.addItem(contentItem);++ if (content.sessionId) {+ await this._db.noteHistory.add(contentItem.noteId, content.sessionId, {+ data: contentItem.data,+ type: contentItem.type,+ });+ }return id;}diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.jsindex 73de73a49..120786986 100644--- a/packages/core/collections/notes.js+++ b/packages/core/collections/notes.js@@ -51,6 +51,7 @@ export default class Notes extends Collection {if (!content) throw new Error("Invalid content type.");note.contentId = await this._db.content.add({noteId: id,+ sessionId: note.sessionId,id: note.contentId,type,data,