From dd72e0ded0e69154661543809176746c8baa6df7 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 21 Feb 2021 12:02:22 +0100 Subject: [PATCH] broadcast lichess game IDs - done --- app/views/relay/form.scala | 8 ++++++-- modules/i18n/src/main/I18nKeys.scala | 3 ++- modules/relay/src/main/Env.scala | 1 + modules/relay/src/main/RelayFetch.scala | 14 +++++++++----- modules/round/src/main/GameProxyRepo.scala | 3 +++ translation/source/broadcast.xml | 3 ++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/views/relay/form.scala b/app/views/relay/form.scala index 5cd2dcbd35..2eeded7f1f 100644 --- a/app/views/relay/form.scala +++ b/app/views/relay/form.scala @@ -74,8 +74,12 @@ object form { else form3.hidden(form("official")), form3.group( form("syncUrl"), - sourceUrl(), - help = sourceUrlHelp().some + sourceUrlOrGameIds(), + help = frag( + sourceUrlHelp(), + br, + gameIdsHelp() + ).some )(form3.input(_)), form("syncUrl").value.exists(LccRegex.matches) option { form3.group(form("syncUrlRound"), roundNumber())( diff --git a/modules/i18n/src/main/I18nKeys.scala b/modules/i18n/src/main/I18nKeys.scala index 93633ab208..f35773fe7e 100644 --- a/modules/i18n/src/main/I18nKeys.scala +++ b/modules/i18n/src/main/I18nKeys.scala @@ -1375,8 +1375,9 @@ val `eventName` = new I18nKey("broadcast:eventName") val `eventDescription` = new I18nKey("broadcast:eventDescription") val `fullDescription` = new I18nKey("broadcast:fullDescription") val `fullDescriptionHelp` = new I18nKey("broadcast:fullDescriptionHelp") -val `sourceUrl` = new I18nKey("broadcast:sourceUrl") +val `sourceUrlOrGameIds` = new I18nKey("broadcast:sourceUrlOrGameIds") val `sourceUrlHelp` = new I18nKey("broadcast:sourceUrlHelp") +val `gameIdsHelp` = new I18nKey("broadcast:gameIdsHelp") val `roundNumber` = new I18nKey("broadcast:roundNumber") val `startDate` = new I18nKey("broadcast:startDate") val `startDateHelp` = new I18nKey("broadcast:startDateHelp") diff --git a/modules/relay/src/main/Env.scala b/modules/relay/src/main/Env.scala index f456774ed8..5c9390fe44 100644 --- a/modules/relay/src/main/Env.scala +++ b/modules/relay/src/main/Env.scala @@ -14,6 +14,7 @@ final class Env( chapterRepo: lila.study.ChapterRepo, gameRepo: lila.game.GameRepo, pgnDump: lila.game.PgnDump, + gameProxy: lila.round.GameProxyRepo, cacheApi: lila.memo.CacheApi, slackApi: lila.irc.SlackApi, baseUrl: BaseUrl diff --git a/modules/relay/src/main/RelayFetch.scala b/modules/relay/src/main/RelayFetch.scala index 713cfa45ea..25cbce09b7 100644 --- a/modules/relay/src/main/RelayFetch.scala +++ b/modules/relay/src/main/RelayFetch.scala @@ -15,6 +15,7 @@ import lila.memo.CacheApi import lila.study.MultiPgn import lila.tree.Node.Comments import lila.game.{ Game, GameRepo, PgnDump } +import lila.round.GameProxyRepo final private class RelayFetch( sync: RelaySync, @@ -23,6 +24,7 @@ final private class RelayFetch( formatApi: RelayFormatApi, gameRepo: GameRepo, pgnDump: PgnDump, + gameProxy: GameProxyRepo, ws: StandaloneWSClient ) extends Actor { @@ -143,11 +145,13 @@ final private class RelayFetch( private def fetchGames(relay: Relay): Fu[RelayGames] = relay.sync.upstream ?? { case UpstreamIds(ids) => - gameRepo.gamesFromSecondary(ids) flatMap gameRepo.withInitialFens flatMap { - _.map { case (game, fen) => - pgnDump(game, fen, gameIdsUpstreamPgnFlags).dmap(_.render) - }.sequenceFu dmap MultiPgn.apply - } flatMap RelayFetch.multiPgnToGames.apply + gameRepo.gamesFromSecondary(ids) flatMap + gameProxy.upgradeIfPresent flatMap + gameRepo.withInitialFens flatMap { + _.map { case (game, fen) => + pgnDump(game, fen, gameIdsUpstreamPgnFlags).dmap(_.render) + }.sequenceFu dmap MultiPgn.apply + } flatMap RelayFetch.multiPgnToGames.apply case url: UpstreamUrl => cache.asMap .compute( diff --git a/modules/round/src/main/GameProxyRepo.scala b/modules/round/src/main/GameProxyRepo.scala index 48b3499f65..4ff6eb244a 100644 --- a/modules/round/src/main/GameProxyRepo.scala +++ b/modules/round/src/main/GameProxyRepo.scala @@ -30,6 +30,9 @@ final class GameProxyRepo( def upgradeIfPresent(pov: Pov): Fu[Pov] = upgradeIfPresent(pov.game).dmap(_ pov pov.color) + def upgradeIfPresent(games: List[Game]): Fu[List[Game]] = + games.map(upgradeIfPresent).sequenceFu + // update the proxied game def updateIfPresent = roundSocket.updateIfPresent _ diff --git a/translation/source/broadcast.xml b/translation/source/broadcast.xml index b1bf8c72f0..dce697322a 100644 --- a/translation/source/broadcast.xml +++ b/translation/source/broadcast.xml @@ -10,8 +10,9 @@ Short event description Full event description Optional long description of the broadcast. %1$s is available. Length must be less than %2$s characters. - Source URL + Source URL, or game IDs URL that Lichess will check to get PGN updates. It must be publicly accessible from the Internet. + Alternatively, you can enter up to 64 lichess game IDs, separated by spaces. Round number Start date in your own timezone Optional, if you know when the event starts