expose tournament socket version in the API, on demand - closes #1563
This commit is contained in:
parent
a11dcffe57
commit
9d36f3bba4
|
@ -53,18 +53,21 @@ object Tournament extends LilaController {
|
|||
negotiate(
|
||||
html = repo byId id flatMap {
|
||||
_.fold(tournamentNotFound.fuccess) { tour =>
|
||||
env.version(tour.id) zip env.jsonView(tour, page, ctx.userId, none) zip chatOf(tour) map {
|
||||
case ((version, data), chat) => html.tournament.show(tour, version, data, chat)
|
||||
env.version(tour.id) zip chatOf(tour) flatMap {
|
||||
case (version, chat) => env.jsonView(tour, page, ctx.userId, none, version.some) map {
|
||||
html.tournament.show(tour, _, chat)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
api = _ => repo byId id flatMap {
|
||||
case None => NotFound(Json.obj("error" -> "No such tournament")).fuccess
|
||||
case Some(tour) => get("playerInfo") ?? {
|
||||
env.api.playerInfo(tour.id, _)
|
||||
} flatMap { playerInfoExt =>
|
||||
env.jsonView(tour, page, ctx.userId, playerInfoExt)
|
||||
} map { Ok(_) }
|
||||
case Some(tour) =>
|
||||
get("playerInfo").?? { env.api.playerInfo(tour.id, _) } zip
|
||||
getBool("socketVersion").??(env version tour.id map some) flatMap {
|
||||
case (playerInfoExt, socketVersion) =>
|
||||
env.jsonView(tour, page, ctx.userId, playerInfoExt, socketVersion)
|
||||
} map { Ok(_) }
|
||||
} map (_ as JSON)
|
||||
) map NoCache
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@(tour: Tournament, socketVersion: Int, data: play.api.libs.json.JsObject, chat: Option[lila.chat.UserChat])(implicit ctx: Context)
|
||||
@(tour: Tournament, data: play.api.libs.json.JsObject, chat: Option[lila.chat.UserChat])(implicit ctx: Context)
|
||||
|
||||
@underchat = {
|
||||
<div class="watchers" data-icon="v">
|
||||
|
@ -13,7 +13,6 @@ lichess = lichess || {};
|
|||
lichess.tournament = {
|
||||
data: @Html(play.api.libs.json.Json.stringify(data)),
|
||||
i18n: @jsI18n(),
|
||||
socketVersion: @socketVersion,
|
||||
userId: @Html(ctx.userId.fold("null")(id => s""""$id""""))
|
||||
};
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ final class JsonView(
|
|||
tour: Tournament,
|
||||
page: Option[Int],
|
||||
me: Option[String],
|
||||
playerInfoExt: Option[PlayerInfoExt]): Fu[JsObject] = for {
|
||||
playerInfoExt: Option[PlayerInfoExt],
|
||||
socketVersion: Option[Int]): Fu[JsObject] = for {
|
||||
data <- cachableData(tour.id)
|
||||
myInfo <- me ?? { PlayerRepo.playerInfo(tour.id, _) }
|
||||
stand <- (myInfo, page) match {
|
||||
|
@ -59,7 +60,8 @@ final class JsonView(
|
|||
"featured" -> data.featured,
|
||||
"podium" -> data.podium,
|
||||
"playerInfo" -> playerInfoJson,
|
||||
"quote" -> tour.isCreated.option(lila.quote.Quote.one(tour.id))
|
||||
"quote" -> tour.isCreated.option(lila.quote.Quote.one(tour.id)),
|
||||
"socketVersion" -> socketVersion
|
||||
).noNull
|
||||
|
||||
def standing(tour: Tournament, page: Int): Fu[JsObject] =
|
||||
|
|
|
@ -2209,7 +2209,7 @@ lichess.unique = function(xs) {
|
|||
});
|
||||
var tournament;
|
||||
lichess.socket = new lichess.StrongSocket(
|
||||
'/tournament/' + cfg.data.id + '/socket/v1', cfg.socketVersion, {
|
||||
'/tournament/' + cfg.data.id + '/socket/v1', cfg.data.socketVersion, {
|
||||
receive: function(t, d) {
|
||||
tournament.socketReceive(t, d)
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue