make sure to use the merged chapter node - closes #8220

pull/8400/head
Thibault Duplessis 2021-03-17 11:14:27 +01:00
parent 2b42af621a
commit 0a1da8a2e1
1 changed files with 22 additions and 20 deletions

View File

@ -225,36 +225,38 @@ final class StudyApi(
opts: MoveOpts,
relay: Option[Chapter.Relay]
)(who: Who): Funit = {
val node = rawNode.withoutChildren
val singleNode = rawNode.withoutChildren
def failReload() = reloadSriBecauseOf(study, who.sri, position.chapter.id)
if (position.chapter.isOverweight) {
logger.info(s"Overweight chapter ${study.id}/${position.chapter.id}")
fuccess(failReload())
} else
position.chapter.addNode(node, position.path, relay) match {
position.chapter.addNode(singleNode, position.path, relay) match {
case None =>
failReload()
fufail(s"Invalid addNode ${study.id} ${position.ref} $node")
fufail(s"Invalid addNode ${study.id} ${position.ref} $singleNode")
case Some(chapter) =>
chapter.root.nodeAt(position.path) ?? { parent =>
val newPosition = position.ref + node
chapterRepo.addSubTree(node, parent addChild node, position.path)(chapter) >>
(relay ?? { chapterRepo.setRelay(chapter.id, _) }) >>
(opts.sticky ?? studyRepo.setPosition(study.id, newPosition)) >>
updateConceal(study, chapter, newPosition) >> {
sendTo(study.id)(
_.addNode(
position.ref,
node,
chapter.setup.variant,
sticky = opts.sticky,
relay = relay,
who
parent.children.get(singleNode.id) ?? { node =>
val newPosition = position.ref + node
chapterRepo.addSubTree(node, parent addChild node, position.path)(chapter) >>
(relay ?? { chapterRepo.setRelay(chapter.id, _) }) >>
(opts.sticky ?? studyRepo.setPosition(study.id, newPosition)) >>
updateConceal(study, chapter, newPosition) >> {
sendTo(study.id)(
_.addNode(
position.ref,
node,
chapter.setup.variant,
sticky = opts.sticky,
relay = relay,
who
)
)
)
(opts.promoteToMainline && !Path.isMainline(chapter.root, newPosition.path)) ??
promote(study.id, position.ref + node, toMainline = true)(who)
}
(opts.promoteToMainline && !Path.isMainline(chapter.root, newPosition.path)) ??
promote(study.id, position.ref + node, toMainline = true)(who)
}
}
}
}
}