Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/master' into next60

zadamecd2a5cbace1
diff --cc src/services/tree.js
index ac12481ca2,fd3c034c00..5c37986806
--- a/src/services/tree.js
+++ b/src/services/tree.js
@@@ -4,19 -4,42 +4,19 @@@ const sql = require('./sql')
const log = require('./log');
const BBranch = require('../becca/entities/bbranch');
const entityChangesService = require('./entity_changes');
-const protectedSessionService = require('./protected_session');
const becca = require('../becca/becca');
-function getNotes(noteIds) {
- // we return also deleted notes which have been specifically asked for
- const notes = sql.getManyRows(`
- SELECT
- noteId,
- title,
- isProtected,
- type,
- mime,
- isDeleted
- FROM notes
- WHERE noteId IN (???)`, noteIds);
-
- protectedSessionService.decryptNotes(notes);
-
- notes.forEach(note => {
- note.isProtected = !!note.isProtected
- });
-
- return notes;
-}
-
function validateParentChild(parentNoteId, childNoteId, branchId = null) {
if (['root', '_hidden', '_share', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(childNoteId)) {
- return { success: false, message: `Cannot change this note's location.`};
+ return { branch: null, success: false, message: `Cannot change this note's location.`};
}
if (parentNoteId === 'none') {
// this shouldn't happen
- return { success: false, message: `Cannot move anything into 'none' parent.` };
+ return { branch: null, success: false, message: `Cannot move anything into 'none' parent.` };
}
- const existing = getExistingBranch(parentNoteId, childNoteId);
+ const existing = becca.getBranchFromChildAndParent(childNoteId, parentNoteId);
if (existing && (branchId === null || existing.branchId !== branchId)) {
const parentNote = becca.getNote(parentNoteId);
@@@ -28,8 -52,9 +29,9 @@@
};
}
- if (!checkTreeCycle(parentNoteId, childNoteId)) {
+ if (wouldAddingBranchCreateCycle(parentNoteId, childNoteId)) {
return {
+ branch: null,
success: false,
message: 'Moving/cloning note here would create cycle.'
};
@@@ -42,9 -68,20 +45,9 @@@
};
}
- return { success: true };
+ return { branch: null, success: true };
}
-function getExistingBranch(parentNoteId, childNoteId) {
- const branchId = sql.getValue(`
- SELECT branchId
- FROM branches
- WHERE noteId = ?
- AND parentNoteId = ?
- AND isDeleted = 0`, [childNoteId, parentNoteId]);
-
- return becca.getBranch(branchId);
-}
-
/**
* Tree cycle can be created when cloning or when moving existing clone. This method should detect both cases.
*/