delete initial chapter when syncing relay

pull/3627/head
Thibault Duplessis 2017-10-01 18:25:44 -05:00
parent f336c4e7c1
commit e694674b62
1 changed files with 7 additions and 3 deletions

View File

@ -21,7 +21,11 @@ private final class RelaySync(
_ <- lila.common.Future.traverseSequentially(games) { game =>
chapters.find(_.tags(idTag) has game.id) match {
case Some(chapter) => updateChapter(study, chapter, game)
case None => createChapter(study, game)
case None => createChapter(study, game) flatMap { chapter =>
chapters.find(_.isEmptyInitial).ifTrue(chapter.order == 2) ?? { initial =>
studyApi.deleteChapter(study.ownerId, study.id, initial.id, socketUid)
}
}
}
}
} yield ()
@ -71,7 +75,7 @@ private final class RelaySync(
}
}
private def createChapter(study: Study, game: RelayGame): Funit =
private def createChapter(study: Study, game: RelayGame): Fu[Chapter] =
chapterRepo.nextOrderByStudy(study.id) flatMap { order =>
val chapter = Chapter.make(
studyId = study.id,
@ -89,7 +93,7 @@ private final class RelaySync(
gamebook = false,
conceal = none
)
studyApi.doAddChapter(study, chapter, sticky = false, uid = socketUid)
studyApi.doAddChapter(study, chapter, sticky = false, uid = socketUid) inject chapter
}
private def multiGamePgnToGames(multiPgn: MultiPgn, logger: lila.log.Logger): Try[List[RelayGame]] =