mirror of
https://github.com/zadam/trilium.git
synced 2025-01-25 00:18:15 +08:00
fix handling of note history - when saving note history we save previous state, not current
This commit is contained in:
parent
4f47c4d6e9
commit
f1256423ac
3 changed files with 9 additions and 10 deletions
|
@ -27,7 +27,7 @@ const noteHistory = (function() {
|
|||
historyItems = await server.get('notes-history/' + noteId);
|
||||
|
||||
for (const item of historyItems) {
|
||||
const dateModified = getDateFromTS(item.date_modified_to);
|
||||
const dateModified = getDateFromTS(item.date_modified_from);
|
||||
|
||||
$("#note-history-list").append($('<option>', {
|
||||
value: item.note_history_id,
|
||||
|
|
|
@ -1 +1 @@
|
|||
module.exports = { build_date:"2017-12-06T21:05:03-05:00", build_revision: "bbd177481523bf6d7c9388b0ddf65af7f5c61e6b" };
|
||||
module.exports = { build_date:"2017-12-06T21:44:45-05:00", build_revision: "4f47c4d6e919aefd303617ac459cea41a1761385" };
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue