share tree should include branch prefixes, fixes #4096

This commit is contained in:
zadam
2023-07-17 22:19:03 +02:00
parent 84c4b368c8
commit d6a4f1db13
5 changed files with 34 additions and 15 deletions

View File

@@ -9,21 +9,28 @@ const contentRenderer = require("./content_renderer");
const assetPath = require("../services/asset_path");
const appPath = require("../services/app_path");
/**
* @param {SNote} note
* @return {{note: SNote, branch: SBranch}|{}}
*/
function getSharedSubTreeRoot(note) {
if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
// share root itself is not shared
return null;
return {};
}
// every path leads to share root, but which one to choose?
// for the sake of simplicity, URLs are not note paths
const parentNote = note.getParentNotes()[0];
const parentBranch = note.getParentBranches()[0];
if (parentNote.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
return note;
if (parentBranch.parentNoteId === shareRoot.SHARE_ROOT_NOTE_ID) {
return {
note,
branch: parentBranch
};
}
return getSharedSubTreeRoot(parentNote);
return getSharedSubTreeRoot(parentBranch.getParentNote());
}
function addNoIndexHeader(note, res) {

View File

@@ -52,6 +52,11 @@ class SBranch extends AbstractShacaEntity {
get parentNote() {
return this.shaca.notes[this.parentNoteId];
}
/** @returns {SNote} */
getParentNote() {
return this.parentNote;
}
}
module.exports = SBranch;

View File

@@ -68,6 +68,13 @@ class SNote extends AbstractShacaEntity {
return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
}
/** @returns {SBranch[]} */
getVisibleChildBranches() {
return this.getChildBranches()
.filter(branch => !branch.isHidden
&& !branch.getNote().isLabelTruthy('shareHiddenFromTree'));
}
/** @returns {SNote[]} */
getParentNotes() {
return this.parents;
@@ -80,10 +87,8 @@ class SNote extends AbstractShacaEntity {
/** @returns {SNote[]} */
getVisibleChildNotes() {
return this.getChildBranches()
.filter(branch => !branch.isHidden)
.map(branch => branch.getNote())
.filter(childNote => !childNote.isLabelTruthy('shareHiddenFromTree'));
return this.getVisibleChildBranches()
.map(branch => branch.getNote());
}
/** @returns {boolean} */