avoid commented practice chapters - fixes #2955

This commit is contained in:
Thibault Duplessis 2017-04-18 19:08:11 +02:00
parent cd69cb17f0
commit dd7aaf8aa4
2 changed files with 9 additions and 5 deletions

View file

@ -23,9 +23,9 @@ final class PracticeApi(
def getStudyWithFirstOngoingChapter(user: Option[User], studyId: Study.Id): Fu[Option[UserStudy]] = for {
up <- get(user)
chapters <- studyApi.chapterMetadatas(studyId)
chapterId = up.progress firstOngoingIn chapters.map(_.id)
studyOption <- chapterId.fold(studyApi byIdWithFirstChapter studyId) {
studyApi.byIdWithChapter(studyId, _)
chapter = up.progress firstOngoingIn chapters
studyOption <- chapter.fold(studyApi byIdWithFirstChapter studyId) { chapter =>
studyApi.byIdWithChapter(studyId, chapter.id)
}
} yield makeUserStudy(studyOption, up, chapters)

View file

@ -28,8 +28,12 @@ case class PracticeProgress(
def countDone(chapterIds: List[Chapter.Id]): Int =
chapterIds count chapters.contains
def firstOngoingIn(chapterIds: List[Chapter.Id]): Option[Chapter.Id] =
chapterIds.find(c => !chapters.contains(c)) orElse chapterIds.headOption
def firstOngoingIn(metas: List[Chapter.Metadata]): Option[Chapter.Metadata] =
metas.find { c =>
!chapters.contains(c.id) && !PracticeStructure.isChapterNameCommented(c.name)
} orElse metas.find { c =>
!PracticeStructure.isChapterNameCommented(c.name)
}
}
object PracticeProgress {