mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
fix handling of note history - when saving note history we save previous state, not current
This commit is contained in:
@@ -134,9 +134,6 @@ async function protectNoteHistory(noteId, dataKey, protect) {
|
||||
}
|
||||
|
||||
async function updateNote(noteId, newNote, ctx) {
|
||||
let noteTitleForHistory = newNote.detail.note_title;
|
||||
let noteTextForHistory = newNote.detail.note_text;
|
||||
|
||||
if (newNote.detail.is_protected) {
|
||||
await encryptNote(newNote, ctx);
|
||||
}
|
||||
@@ -147,19 +144,21 @@ async function updateNote(noteId, newNote, ctx) {
|
||||
|
||||
const historyCutoff = now - historySnapshotTimeInterval;
|
||||
|
||||
const existingNoteHistoryId = await sql.getSingleValue("SELECT note_history_id FROM notes_history WHERE note_id = ? AND date_modified_from >= ?", [noteId, historyCutoff]);
|
||||
const existingNoteHistoryId = await sql.getSingleValue("SELECT note_history_id FROM notes_history WHERE note_id = ? AND date_modified_to >= ?", [noteId, historyCutoff]);
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
if (!existingNoteHistoryId && (now - newNote.detail.date_created) >= historySnapshotTimeInterval) {
|
||||
const oldNote = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]);
|
||||
|
||||
const newNoteHistoryId = utils.newNoteHistoryId();
|
||||
|
||||
await sql.insert('notes_history', {
|
||||
note_history_id: newNoteHistoryId,
|
||||
note_id: noteId,
|
||||
note_title: noteTitleForHistory,
|
||||
note_text: noteTextForHistory,
|
||||
is_protected: false, // we don't care about encryption - this will be handled in protectNoteHistory()
|
||||
date_modified_from: now,
|
||||
note_title: oldNote.note_title,
|
||||
note_text: oldNote.note_text,
|
||||
is_protected: oldNote.is_protected,
|
||||
date_modified_from: oldNote.date_modified,
|
||||
date_modified_to: now
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user