Skip to content

Build your personal knowledge base with Trilium Notes

when reloading tree after sync, decrypt tree items if in encryption context

azivnerbd71547258a5
diff --git a/public/javascripts/encryption.js b/public/javascripts/encryption.js
index 44c2d3736d..b55cd9ba19 100644
--- a/public/javascripts/encryption.js
+++ b/public/javascripts/encryption.js
@@ -72,6 +72,22 @@ function computeScrypt(password, salt, callback) {
});
}
+function decryptTreeItems() {
+ if (!isEncryptionAvailable()) {
+ return;
+ }
+
+ for (const noteId of globalAllNoteIds) {
+ const note = getNodeByKey(noteId);
+
+ if (note.data.encryption > 0) {
+ const title = decryptString(note.data.note_title);
+
+ note.setTitle(title);
+ }
+ }
+}
+
$("#encryption-password-form").submit(() => {
const password = $("#encryption-password").val();
$("#encryption-password").val("");
@@ -81,15 +97,7 @@ $("#encryption-password-form").submit(() => {
globalDataKey = key;
- for (const noteId of globalAllNoteIds) {
- const note = getNodeByKey(noteId);
-
- if (note.data.encryption > 0) {
- const title = decryptString(note.data.note_title);
-
- note.setTitle(title);
- }
- }
+ decryptTreeItems();
if (globalEncryptionDeferred !== null) {
globalEncryptionDeferred.resolve();
@@ -97,11 +105,11 @@ $("#encryption-password-form").submit(() => {
globalEncryptionDeferred = null;
}
})
- .catch(reason => {
- console.log(reason);
+ .catch(reason => {
+ console.log(reason);
- alert(reason);
- });
+ alert(reason);
+ });
return false;
});
diff --git a/public/javascripts/status.js b/public/javascripts/status.js
index 205e8f08e5..b600579c3d 100644
--- a/public/javascripts/status.js
+++ b/public/javascripts/status.js
@@ -1,5 +1,5 @@
-function checkStatus() {
- $.ajax({
+async function checkStatus() {
+ const resp = await $.ajax({
url: baseApiUrl + 'status',
type: 'POST',
contentType: "application/json",
@@ -8,18 +8,6 @@ function checkStatus() {
currentNoteId: globalCurrentNote ? globalCurrentNote.detail.note_id : null,
currentNoteDateModified: globalCurrentNoteLoadTime
}),
- success: resp => {
- if (resp.changedTree) {
- loadTree().then(resp => {
- console.log("Reloading tree because of background changes");
-
- // this will also reload the note content
- globalTree.fancytree('getTree').reload(resp.notes);
- });
- }
-
- $("#changesToPushCount").html(resp.changesToPushCount);
- },
statusCode: {
401: () => {
// if the user got logged out then we should display the page
@@ -32,6 +20,19 @@ function checkStatus() {
}
}
});
+
+ if (resp.changedTree) {
+ const treeResp = await loadTree();
+
+ console.log("Reloading tree because of background changes");
+
+ // this will also reload the note content
+ await globalTree.fancytree('getTree').reload(treeResp.notes);
+
+ decryptTreeItems();
+ }
+
+ $("#changesToPushCount").html(resp.changesToPushCount);
}
setInterval(checkStatus, 5 * 1000);
\ No newline at end of file