Prefer showing rematches in /games

pull/9646/head
Albert Ford 2021-08-24 10:12:34 -07:00
parent cb492a9419
commit d007a773a4
No known key found for this signature in database
GPG Key ID: 9C200032321A04A3
6 changed files with 15 additions and 12 deletions

View File

@ -72,12 +72,13 @@ final class Tv(
}
}
def gameReplacement = gameChannelReplacement(lila.tv.Tv.Channel.Best.key, _)
def gameReplacement(gameId: String, exclude: List[String]) =
gameChannelReplacement(lila.tv.Tv.Channel.Best.key, gameId, exclude)
def gameChannelReplacement(chanKey: String, exclude: List[String]) =
def gameChannelReplacement(chanKey: String, gameId: String, exclude: List[String]) =
Open { implicit ctx =>
val gameFu = lila.tv.Tv.Channel.byKey.get(chanKey) ?? { channel =>
env.tv.tv.getReplacementGame(channel, exclude)
env.tv.tv.getReplacementGame(channel, gameId, exclude)
}
OptionResult(gameFu) { game =>
JsonOk {

View File

@ -31,8 +31,8 @@ GET /tv/:chanKey controllers.Tv.onChannel(chanKey: String)
GET /tv/$gameId<\w{8}>/$color<white|black>/sides controllers.Tv.sides(gameId: String, color: String)
GET /games controllers.Tv.games
GET /games/:chanKey controllers.Tv.gamesChannel(chanKey: String)
GET /games/replacement controllers.Tv.gameReplacement(exclude: List[String])
GET /games/:chanKey/replacement controllers.Tv.gameChannelReplacement(chanKey: String, exclude: List[String])
GET /games/replacement/$gameId<\w{8}> controllers.Tv.gameReplacement(gameId: String, exclude: List[String])
GET /games/:chanKey/replacement/$gameId<\w{8}> controllers.Tv.gameChannelReplacement(chanKey: String, gameId: String, exclude: List[String])
GET /api/tv/channels controllers.Tv.channels
GET /api/tv/feed controllers.Tv.feed
GET /api/tv/:chanKey controllers.Tv.apiGamesChannel(chanKey: String)

View File

@ -38,7 +38,8 @@ final private[tv] class ChannelSyncActor(
case GetGameIds(max, promise) => promise success manyIds.take(max)
case GetReplacementGameId(exclude, promise) => promise success manyIds.find(!exclude.contains(_))
case GetReplacementGameId(oldId, exclude, promise) =>
promise success { rematchOf(oldId) ++ manyIds find { !exclude.contains(_) } }
case SetGame(game) =>
onSelect(TvSyncActor.Selected(channel, game))
@ -116,7 +117,7 @@ object ChannelSyncActor {
case class GetGameId(promise: Promise[Option[Game.ID]])
case class GetGameIds(max: Int, promise: Promise[List[Game.ID]])
case class GetReplacementGameId(exclude: List[Game.ID], promise: Promise[Option[Game.ID]])
case class GetReplacementGameId(oldId: Game.ID, exclude: List[Game.ID], promise: Promise[Option[Game.ID]])
private case class SetGame(game: Game)
case class GetGameIdAndHistory(promise: Promise[GameIdAndHistory])

View File

@ -18,9 +18,9 @@ final class Tv(
def getGame(channel: Tv.Channel): Fu[Option[Game]] =
trouper.ask[Option[Game.ID]](TvSyncActor.GetGameId(channel, _)) flatMap { _ ?? roundProxyGame }
def getReplacementGame(channel: Tv.Channel, exclude: List[Game.ID]): Fu[Option[Game]] =
def getReplacementGame(channel: Tv.Channel, oldId: Game.ID, exclude: List[Game.ID]): Fu[Option[Game]] =
trouper
.ask[Option[Game.ID]](TvSyncActor.GetReplacementGameId(channel, exclude, _))
.ask[Option[Game.ID]](TvSyncActor.GetReplacementGameId(channel, oldId, exclude, _))
.flatMap { _ ?? roundProxyGame }
def getGameAndHistory(channel: Tv.Channel): Fu[Option[(Game, List[Pov])]] =

View File

@ -42,8 +42,8 @@ final private[tv] class TvSyncActor(
case GetGameIds(channel, max, promise) =>
forward(channel, ChannelSyncActor.GetGameIds(max, promise))
case GetReplacementGameId(channel, exclude, promise) =>
forward(channel, ChannelSyncActor.GetReplacementGameId(exclude, promise))
case GetReplacementGameId(channel, oldId, exclude, promise) =>
forward(channel, ChannelSyncActor.GetReplacementGameId(oldId, exclude, promise))
case GetChampions(promise) => promise success Tv.Champions(channelChampions)
@ -108,6 +108,7 @@ private[tv] object TvSyncActor {
case class GetGameIds(channel: Tv.Channel, max: Int, promise: Promise[List[Game.ID]])
case class GetReplacementGameId(
channel: Tv.Channel,
oldId: Game.ID,
exclude: List[Game.ID],
promise: Promise[Option[Game.ID]]
)

View File

@ -18,7 +18,7 @@ function requestReplacementGame() {
// Use requestAnimationFrame to avoid requesting games in background tabs
requestAnimationFrame(() => {
const url = new URL(`${window.location.pathname}/replacement`, window.location.origin);
const url = new URL(`${window.location.pathname}/replacement/${oldId}`, window.location.origin);
$('.mini-game').each((_i, el) => url.searchParams.append('exclude', el.dataset.live!));
xhr
.json(url.toString())