send featured game through websockets
This commit is contained in:
parent
2c3a253c89
commit
ac48dae13d
|
@ -48,10 +48,4 @@ object Game extends LilaController with BaseGame {
|
||||||
Ok(html.game.analysed(analysePaginator games page, makeListMenu))
|
Ok(html.game.analysed(analysePaginator games page, makeListMenu))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def featuredJs(id: String) = Open { implicit ctx ⇒
|
|
||||||
IOk(gameRepo game id map { gameOption =>
|
|
||||||
html.game.featuredJs(gameOption)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,11 @@ final class Featured(
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getOne = oneId flatMap fetch filter valid orElse {
|
private def getOne = oneId flatMap fetch filter valid orElse {
|
||||||
feature ~ { o ⇒
|
feature ~ { newOne ⇒
|
||||||
val newOneId = o map (_.id)
|
oneId = newOne map (_.id)
|
||||||
newOneId foreach { newId ⇒
|
newOne foreach { game ⇒
|
||||||
lobbyRef ! ChangeFeatured(oneId, newId)
|
lobbyRef ! ChangeFeatured(views.html.game.featuredJsNoCtx(game).toString)
|
||||||
}
|
}
|
||||||
oneId = newOneId
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,4 +101,15 @@ trait GameHelper { self: I18nHelper with UserHelper with StringHelper with AiHel
|
||||||
Forsyth exportBoard game.toChess.board,
|
Forsyth exportBoard game.toChess.board,
|
||||||
game.lastMove | "")
|
game.lastMove | "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def gameFenNoCtx(game: DbGame, color: Color) = Html {
|
||||||
|
var live = game.isBeingPlayed
|
||||||
|
"""<a href="%s" class="mini_board parse_fen %s" data-live="%s" data-color="%s" data-fen="%s" data-lastmove="%s"></a>""".format(
|
||||||
|
routes.Round.watcher(game.id, color.name),
|
||||||
|
live.fold("live live_" + game.id, ""),
|
||||||
|
live.fold(game.id, ""),
|
||||||
|
color.name,
|
||||||
|
Forsyth exportBoard game.toChess.board,
|
||||||
|
game.lastMove | "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,13 +61,11 @@ final class Hub(
|
||||||
members.values filter (_ ownsHook hook) foreach fn
|
members.values filter (_ ownsHook hook) foreach fn
|
||||||
}
|
}
|
||||||
|
|
||||||
case ChangeFeatured(oldId, newId) ⇒ notifyFeatured(oldId, newId)
|
case ChangeFeatured(html) ⇒ notifyFeatured(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
def notifyFeatured(oldId: Option[String], newId: String) {
|
def notifyFeatured(html: String) {
|
||||||
val msg = makeMessage("featured", JsObject(Seq(
|
val msg = makeMessage("featured", JsString(html))
|
||||||
"oldId" -> oldId.fold(JsString(_), JsNull),
|
|
||||||
"newId" -> JsString(newId))))
|
|
||||||
members.values foreach (_.channel push msg)
|
members.values foreach (_.channel push msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,5 +28,5 @@ case class Quit(uid: String)
|
||||||
case class SendTo(userId: String, message: JsObject)
|
case class SendTo(userId: String, message: JsObject)
|
||||||
case class Fen(gameId: String, fen: String, lastMove: Option[String])
|
case class Fen(gameId: String, fen: String, lastMove: Option[String])
|
||||||
case class LiveGames(uid: String, gameIds: List[String])
|
case class LiveGames(uid: String, gameIds: List[String])
|
||||||
case class ChangeFeatured(oldId: Option[String], newId: String)
|
case class ChangeFeatured(html: String)
|
||||||
case class Resync(uid: String)
|
case class Resync(uid: String)
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
@(gameOption: Option[DbGame])(implicit ctx: Context)
|
@(g: DbGame)(implicit ctx: Context)
|
||||||
|
@gameFen(g, g.creator.color)
|
||||||
<div class="featured_game" data-href="@routes.Game.featuredJs("")">
|
<div class="vstext">@usernameWithElo(g.creator) - @usernameWithElo(g.invited)</div>
|
||||||
@gameOption.map { game =>
|
|
||||||
@gameFen(game, game.creator.color)
|
|
||||||
<div class="vstext">
|
|
||||||
@usernameWithElo(game.creator) - @usernameWithElo(game.invited)<br />
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
3
app/views/game/featuredJsNoCtx.scala.html
Normal file
3
app/views/game/featuredJsNoCtx.scala.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
@(g: DbGame)
|
||||||
|
@gameFenNoCtx(g, g.creator.color)
|
||||||
|
<div class="vstext">@usernameWithElo(g.creator) - @usernameWithElo(g.invited)</div>
|
|
@ -26,7 +26,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@underchat = {
|
@underchat = {
|
||||||
@game.featuredJs(featured)
|
<div id="featured_game">
|
||||||
|
@featured.map { g =>
|
||||||
|
@game.featuredJs(g)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@baseline = {
|
@baseline = {
|
||||||
|
|
|
@ -8,7 +8,6 @@ GET /games/checkmate controllers.Game.checkmate(page: Int ?= 1)
|
||||||
GET /games/bookmark controllers.Game.bookmark(page: Int ?= 1)
|
GET /games/bookmark controllers.Game.bookmark(page: Int ?= 1)
|
||||||
GET /games/popular controllers.Game.popular(page: Int ?= 1)
|
GET /games/popular controllers.Game.popular(page: Int ?= 1)
|
||||||
GET /games/analysed controllers.Game.analysed(page: Int ?= 1)
|
GET /games/analysed controllers.Game.analysed(page: Int ?= 1)
|
||||||
GET /games/featured/js controllers.Game.featuredJs(id: String ?= "")
|
|
||||||
|
|
||||||
# Search
|
# Search
|
||||||
GET /games/search controllers.Search.form(page: Int ?= 1)
|
GET /games/search controllers.Search.form(page: Int ?= 1)
|
||||||
|
|
|
@ -233,18 +233,9 @@ $(function() {
|
||||||
$("table.tournaments").html(data);
|
$("table.tournaments").html(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeFeatured(data) {
|
function changeFeatured(html) {
|
||||||
$('div.featured_game').each(function() {
|
$('#featured_game').html(html);
|
||||||
var $featured = $(this);
|
$('body').trigger('lichess.content_loaded');
|
||||||
$.get(
|
|
||||||
$featured.data("href"),
|
|
||||||
{ id: data.newId },
|
|
||||||
function(html) {
|
|
||||||
$featured.replaceWith(html);
|
|
||||||
$('body').trigger('lichess.content_loaded');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTimeline(data) {
|
function renderTimeline(data) {
|
||||||
|
|
|
@ -184,7 +184,7 @@ div.hooks a.user_link {
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.featured_game div.vstext {
|
#featured_game div.vstext {
|
||||||
margin-top: 0.7em;
|
margin-top: 0.7em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
1
todo
1
todo
|
@ -47,4 +47,3 @@ save game prefs in cookie
|
||||||
redis pubsub / rabbitmq for ai
|
redis pubsub / rabbitmq for ai
|
||||||
IP smart tools for admins
|
IP smart tools for admins
|
||||||
lsof show the open websockets on prod. The recurrent bug could come from the open descriptors limit (ulimit -n)
|
lsof show the open websockets on prod. The recurrent bug could come from the open descriptors limit (ulimit -n)
|
||||||
send featured fen through websocket instead of multiple ajax call
|
|
||||||
|
|
Loading…
Reference in a new issue