synchronize relay PGN tags
parent
a5d449d4d6
commit
2760023ead
|
@ -2,7 +2,7 @@ package lila.relay
|
|||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import chess.format.pgn.Tag
|
||||
import chess.format.pgn.{ Tag, Tags }
|
||||
import lila.common.{ LilaException, Chronometer }
|
||||
import lila.socket.Socket.Uid
|
||||
import lila.study._
|
||||
|
@ -34,19 +34,9 @@ private final class RelaySync(
|
|||
}
|
||||
|
||||
private def updateChapter(study: Study, chapter: Chapter, game: RelayGame): Fu[NbMoves] =
|
||||
updateChapterStatus(study, chapter, game) >>
|
||||
updateChapterTags(study, chapter, game) >>
|
||||
updateChapterTree(study, chapter, game)
|
||||
|
||||
private def updateChapterStatus(study: Study, chapter: Chapter, game: RelayGame): Funit =
|
||||
game.end ?? { end =>
|
||||
(chapter.tags(_.Result).fold(true)(end.resultText !=)) ?? studyApi.setTag(
|
||||
userId = chapter.ownerId,
|
||||
studyId = study.id,
|
||||
lila.study.actorApi.SetTag(chapter.id, "result", end.resultText),
|
||||
uid = socketUid
|
||||
)
|
||||
}
|
||||
|
||||
private def updateChapterTree(study: Study, chapter: Chapter, game: RelayGame): Fu[NbMoves] = {
|
||||
game.root.mainline.foldLeft(Path.root -> none[Node]) {
|
||||
case ((parentPath, None), gameNode) =>
|
||||
|
@ -94,6 +84,28 @@ private final class RelaySync(
|
|||
}
|
||||
}
|
||||
|
||||
private def updateChapterTags(study: Study, chapter: Chapter, game: RelayGame): Funit = {
|
||||
val gameTags = game.tags.value.foldLeft(Tags(Nil)) {
|
||||
case (newTags, tag) =>
|
||||
if (!chapter.tags(_ => tag.name).has(tag.value)) newTags + tag
|
||||
else newTags
|
||||
}
|
||||
val tags = game.end
|
||||
.ifFalse(gameTags(_.Result).isDefined)
|
||||
.filterNot(end => chapter.tags(_.Result).??(end.resultText ==))
|
||||
.fold(gameTags) { end =>
|
||||
gameTags + Tag(_.Result, end.resultText)
|
||||
}
|
||||
lila.common.Future.traverseSequentially(tags.value) { tag =>
|
||||
studyApi.setTag(
|
||||
userId = chapter.ownerId,
|
||||
studyId = study.id,
|
||||
lila.study.actorApi.SetTag(chapter.id, tag.name.name, tag.value),
|
||||
uid = socketUid
|
||||
)
|
||||
}.void
|
||||
}
|
||||
|
||||
private def createChapter(study: Study, game: RelayGame): Fu[Chapter] =
|
||||
chapterRepo.nextOrderByStudy(study.id) flatMap { order =>
|
||||
val chapter = Chapter.make(
|
||||
|
|
Loading…
Reference in New Issue