fix study cloning

pull/6611/head
Thibault Duplessis 2020-05-12 09:38:44 -06:00
parent ba14ab758f
commit 7a9bbf3d59
1 changed files with 9 additions and 10 deletions

View File

@ -133,17 +133,16 @@ final class StudyApi(
.mapAsync(4) { c =>
chapterRepo.insert(c) inject c
}
.toMat(Sink.headOption)(Keep.right)
.toMat(Sink.reduce[Chapter] { case (prev, _) => prev })(Keep.right)
.run
.flatMap { (first: Option[Chapter]) =>
first.map(study1.rewindTo) ?? { study =>
studyRepo.insert(study) >>
chatApi.userChat.system(
Chat.Id(study.id.value),
s"Cloned from lichess.org/study/${prev.id}",
_.Study
) inject study.some
}
.flatMap { (first: Chapter) =>
val study = study1 rewindTo first
studyRepo.insert(study) >>
chatApi.userChat.system(
Chat.Id(study.id.value),
s"Cloned from lichess.org/study/${prev.id}",
_.Study
) inject study.some
}
}