Skip to content

Commit

Permalink
send empty broadcast round path for finished games after a hour
Browse files Browse the repository at this point in the history
so that the game is seen rewinded fully
  • Loading branch information
ornicar committed Mar 14, 2024
1 parent 6211159 commit 1d812d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 1 addition & 3 deletions modules/study/src/main/Chapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ case class Chapter(
def updateDenorm: Chapter =
val looksLikeGame = tags.names.exists(_.isDefined) || tags.outcome.isDefined
val newDenorm = looksLikeGame.option:
val node = relay.map(_.path).flatMap(root.nodeAt) | root.lastMainlineNode
val node = relay.map(_.path).filterNot(_.isEmpty).flatMap(root.nodeAt) | root.lastMainlineNode
val clocks = relay.so: r =>
val path = r.path
val parentPath = path.parent.some.filter(_ != path)
Expand Down Expand Up @@ -115,8 +115,6 @@ case class Chapter(

def withoutChildrenIfPractice = if isPractice then copy(root = root.withoutChildren) else this

def relayAndTags = relay.map { Chapter.RelayAndTags(id, _, tags) }

def isOverweight = root.children.countRecursive >= Chapter.maxNodes

object Chapter:
Expand Down
24 changes: 14 additions & 10 deletions modules/study/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class JsonView(
def apply(
study: Study,
previews: ChapterPreview.AsJsons,
currentChapter: Chapter,
chapter: Chapter,
me: Option[User]
) =

Expand All @@ -29,8 +29,12 @@ final class JsonView(

for
liked <- me.so(studyRepo.liked(study, _))
fidePlayers <- fidePlayerApi.players(currentChapter.tags.fideIds)
fidePlayers <- fidePlayerApi.players(chapter.tags.fideIds)
feds = fidePlayers.mapList(_.flatMap(_.fed)).some.filter(_.exists(_.isDefined))
relayPath = chapter.relay
.filter(_.secondsSinceLastMove < 3600 || chapter.tags.outcome.isEmpty)
.map(_.path)
.filterNot(_.isEmpty)
yield Json.toJsObject(study) ++ Json
.obj(
"liked" -> liked,
Expand All @@ -45,20 +49,20 @@ final class JsonView(
"chapters" -> previews,
"chapter" -> Json
.obj(
"id" -> currentChapter.id,
"ownerId" -> currentChapter.ownerId,
"setup" -> currentChapter.setup,
"tags" -> currentChapter.tags,
"id" -> chapter.id,
"ownerId" -> chapter.ownerId,
"setup" -> chapter.setup,
"tags" -> chapter.tags,
"features" -> Json.obj(
"computer" -> allowed(_.computer),
"explorer" -> allowed(_.explorer)
)
)
.add("description", currentChapter.description)
.add("serverEval", currentChapter.serverEval)
.add("relayPath", currentChapter.relay.map(_.path))
.add("description", chapter.description)
.add("serverEval", chapter.serverEval)
.add("relayPath", relayPath)
.add("feds" -> feds)
.pipe(addChapterMode(currentChapter))
.pipe(addChapterMode(chapter))
)
.add("description", study.description)

Expand Down

0 comments on commit 1d812d1

Please sign in to comment.