lila/app/controllers/Lobby.scala

55 lines
1.7 KiB
Scala
Raw Normal View History

2013-03-18 17:36:22 -06:00
package controllers
2013-05-24 08:37:24 -06:00
import play.api.libs.json.Json
import play.api.libs.json.JsValue
import play.api.mvc._
2013-05-08 15:34:37 -06:00
import lila.app._
import lila.common.LilaCookie
2013-05-12 16:48:37 -06:00
import lila.tournament.TournamentRepo
2013-05-24 08:37:24 -06:00
import lila.user.Context
2013-05-08 15:34:37 -06:00
import views._
2013-03-18 17:36:22 -06:00
2013-10-28 12:23:37 -06:00
object Lobby extends LilaController {
2013-03-18 17:36:22 -06:00
2013-05-08 15:34:37 -06:00
def home = Open { implicit ctx
2013-10-28 12:23:37 -06:00
renderHome(Results.Ok).map(_.withHeaders(
2013-05-08 15:34:37 -06:00
CACHE_CONTROL -> "no-cache", PRAGMA -> "no-cache"
))
}
2013-10-28 12:23:37 -06:00
def handleStatus(req: RequestHeader, status: Results.Status): Fu[SimpleResult] =
reqToCtx(req) flatMap { ctx renderHome(status)(ctx) }
2013-10-28 12:23:37 -06:00
def renderHome[A](status: Results.Status)(implicit ctx: Context): Fu[SimpleResult] =
2013-05-08 15:34:37 -06:00
Env.current.preloader(
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds.apply),
2013-07-30 15:02:12 -06:00
tours = TournamentRepo.createdUnprotected,
2013-05-08 19:15:34 -06:00
filter = Env.setup.filter
2013-05-08 15:34:37 -06:00
).map(_.fold(Redirect(_), {
2013-12-21 13:39:31 -07:00
case (preload, entries, gameEntries, posts, tours, featured, leaderboard) status(html.lobby.home(
Json stringify preload, entries, gameEntries, posts, tours, featured, leaderboard)) |> { response
2013-05-08 15:34:37 -06:00
ctx.req.session.data.contains(LilaCookie.sessionId).fold(
response,
response withCookies LilaCookie.makeSessionId(ctx.req)
)
}
}))
2013-05-08 19:27:13 -06:00
def socket = Socket[JsValue] { implicit ctx
get("sri") ?? { uid
2013-05-18 21:31:06 -06:00
Env.lobby.socketHandler(uid = uid, user = ctx.me)
2013-05-08 15:34:37 -06:00
}
}
2013-05-24 08:37:24 -06:00
def timeline = Auth { implicit ctx
me
Env.timeline.getter.userEntries(me.id) map { html.timeline.entries(_) }
}
2013-05-28 16:44:49 -06:00
def timelineMore = Auth { implicit ctx
me
Env.timeline.getter.moreUserEntries(me.id) map { html.timeline.more(_) }
}
2013-03-18 17:36:22 -06:00
}