From 29fb2a842c3f8ba30213b5eb2c4cb3ff7d3c054b Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 18 Apr 2014 09:53:58 +0200 Subject: [PATCH] show current playing game on homepage - WIP --- app/controllers/Lobby.scala | 4 ++-- app/controllers/User.scala | 2 +- app/mashup/Preload.scala | 9 +++++---- app/views/lobby/home.scala.html | 7 ++++++- modules/game/src/main/BinaryFormat.scala | 2 +- modules/game/src/main/Game.scala | 5 +++-- modules/game/src/main/GameRepo.scala | 7 +++++++ modules/game/src/main/Pov.scala | 5 ++++- public/stylesheets/common.css | 15 ++++++++++++++- 9 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/controllers/Lobby.scala b/app/controllers/Lobby.scala index 6c03e5c51a..b65b3af0ee 100644 --- a/app/controllers/Lobby.scala +++ b/app/controllers/Lobby.scala @@ -32,9 +32,9 @@ object Lobby extends LilaController { tours = Env.tournament.allCreatedSorted(true), filter = Env.setup.filter ).map(_.fold(Redirect(_), { - case (preload, entries, posts, tours, featured, leaderboard, progress, puzzle) => + case (preload, entries, posts, tours, featured, leaderboard, progress, puzzle, playing) => val response = status(html.lobby.home( - Json stringify preload, entries, posts, tours, featured, leaderboard, progress, puzzle + Json stringify preload, entries, posts, tours, featured, leaderboard, progress, puzzle, playing )) // the session cookie is required for anon lobby filter storage ctx.req.session.data.contains(LilaCookie.sessionId).fold( diff --git a/app/controllers/User.scala b/app/controllers/User.scala index 76bf622f28..c20e13f1ff 100644 --- a/app/controllers/User.scala +++ b/app/controllers/User.scala @@ -62,7 +62,7 @@ object User extends LilaController { pag ← (filters.query.fold(Env.bookmark.api.gamePaginatorByUser(u, page)) { query => gamePaginator.recentlyCreated(query, filters.cachedNb)(page) }) - playing <- GameRepo nowPlaying u.id map (_.isDefined) + playing <- GameRepo isNowPlaying u.id relation <- ctx.userId ?? { relationApi.relation(_, u.id) } } yield html.user.show(u, info, pag, filters, playing, relation) diff --git a/app/mashup/Preload.scala b/app/mashup/Preload.scala index 39123dae61..6d07034b6d 100644 --- a/app/mashup/Preload.scala +++ b/app/mashup/Preload.scala @@ -9,7 +9,7 @@ import play.api.mvc.Call import controllers.routes import lila.api.Context import lila.forum.PostLiteView -import lila.game.{ Game, GameRepo, Featured } +import lila.game.{ Game, GameRepo, Featured, Pov } import lila.lobby.actorApi.GetOpen import lila.lobby.{ Hook, HookRepo } import lila.relation.RelationApi @@ -30,7 +30,7 @@ final class Preload( timelineEntries: String => Fu[List[Entry]], dailyPuzzle: () => Fu[Option[lila.puzzle.DailyPuzzle]]) { - private type RightResponse = (JsObject, List[Entry], List[PostLiteView], List[Created], Option[Game], List[User], List[User], Option[lila.puzzle.DailyPuzzle]) + private type RightResponse = (JsObject, List[Entry], List[PostLiteView], List[Created], Option[Game], List[User], List[User], Option[lila.puzzle.DailyPuzzle], Option[Pov]) private type Response = Either[Call, RightResponse] def apply( @@ -46,13 +46,14 @@ final class Preload( leaderboard(10) zip progress(10) zip dailyPuzzle() zip + (ctx.me ?? GameRepo.lastPlayingByUser) zip filter map { - case (((((((((hooks, posts), tours), feat), blocks), entries), leaderboard), progress), puzzle), filter) => + case ((((((((((hooks, posts), tours), feat), blocks), entries), leaderboard), progress), puzzle), playing), filter) => (Right((Json.obj( "version" -> history.version, "pool" -> JsArray(hooks map (_.render)), "filter" -> filter.render, "blocks" -> blocks - ), entries, posts, tours, feat, leaderboard, progress, puzzle))) + ), entries, posts, tours, feat, leaderboard, progress, puzzle, playing))) } } diff --git a/app/views/lobby/home.scala.html b/app/views/lobby/home.scala.html index 8b813cedb1..91fc85278e 100644 --- a/app/views/lobby/home.scala.html +++ b/app/views/lobby/home.scala.html @@ -1,4 +1,4 @@ -@(preload: String, userTimeline: List[lila.timeline.Entry], forumRecent: List[lila.forum.PostLiteView], tours: List[lila.tournament.Created], featured: Option[Game], leaderboard: List[User], progress: List[User], puzzle: Option[lila.puzzle.DailyPuzzle])(implicit ctx: Context) +@(preload: String, userTimeline: List[lila.timeline.Entry], forumRecent: List[lila.forum.PostLiteView], tours: List[lila.tournament.Created], featured: Option[Game], leaderboard: List[User], progress: List[User], puzzle: Option[lila.puzzle.DailyPuzzle], playing: Option[Pov])(implicit ctx: Context) @underchat = {