delete note through its entity instead of manually with SQL, closes #303

This commit is contained in:
azivner
2019-01-13 00:24:51 +01:00
parent 348562352c
commit b115a7cf19
5 changed files with 27 additions and 20 deletions

View File

@@ -359,18 +359,8 @@ async function deleteNote(branch) {
const notDeletedBranches = await note.getBranches();
if (notDeletedBranches.length === 0) {
// maybe a bit counter-intuitively, protected notes can be deleted also outside of protected session
// this is because protected notes offer only confidentiality which makes some things simpler - e.g. deletion UI
// to allow this, we just set the isDeleted flag, otherwise saving would fail because of attempt to encrypt
// content with non-existent protected session key
// we don't reset content here, that's postponed and done later to give the user a chance to correct a mistake
await sql.execute("UPDATE notes SET isDeleted = 1 WHERE noteId = ?", [note.noteId]);
// need to manually trigger sync since it's not taken care of by note save
await syncTableService.addNoteSync(note.noteId);
for (const noteRevision of await note.getRevisions()) {
await noteRevision.save();
}
note.isDeleted = true;
await note.save();
for (const childBranch of await note.getChildBranches()) {
await deleteNote(childBranch);