lila/app/controllers/Lobby.scala

69 lines
2.1 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-12-29 02:51:40 -07:00
import lila.api.Context
2013-05-08 15:34:37 -06:00
import lila.app._
import lila.common.LilaCookie
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
2014-02-17 02:12:19 -07:00
def home = Open { implicit ctx =>
2014-12-10 15:15:59 -07:00
renderHome(Results.Ok).map(_.withHeaders(
CACHE_CONTROL -> "no-cache", PRAGMA -> "no-cache"
))
2013-05-08 15:34:37 -06:00
}
def handleStatus(req: RequestHeader, status: Results.Status): Fu[Result] =
2014-02-17 02:12:19 -07:00
reqToCtx(req) flatMap { ctx => renderHome(status)(ctx) }
def renderHome(status: Results.Status)(implicit ctx: Context): Fu[Result] =
2013-05-08 15:34:37 -06:00
Env.current.preloader(
2014-04-18 03:51:19 -06:00
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds),
tours = Env.tournament promotable true,
2014-12-16 17:09:30 -07:00
filter = Env.setup.filter).map {
case (preload, entries, posts, tours, featured, lead, tWinners, puzzle, nowPlaying, seeks, streams, nbRounds) =>
val response = status(html.lobby.home(
2014-06-07 02:42:58 -06:00
Json stringify preload, entries, posts, tours, featured, lead, tWinners,
2014-12-16 17:09:30 -07:00
puzzle, nowPlaying, seeks, streams, Env.blog.lastPostCache.apply, nbRounds
))
// the session cookie is required for anon lobby filter storage
ctx.req.session.data.contains(LilaCookie.sessionId).fold(
response,
response withCookies LilaCookie.makeSessionId(ctx.req)
)
2014-07-17 15:50:53 -06:00
}
2013-05-08 15:34:37 -06:00
def playing = Auth { implicit ctx =>
me =>
lila.game.GameRepo nowPlaying me map { povs =>
html.lobby.playing(povs)
}
}
2014-12-17 17:02:59 -07:00
def seeks = Open { implicit ctx =>
ctx.me.fold(Env.lobby.seekApi.forAnon)(Env.lobby.seekApi.forUser) map { seeks =>
html.lobby.seeks(seeks)
}
}
2014-07-29 14:40:07 -06:00
def socket(apiVersion: Int) = Socket[JsValue] { implicit ctx =>
2014-02-17 02:12:19 -07:00
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
2014-02-17 02:12:19 -07:00
def timeline = Auth { implicit ctx =>
me =>
2013-05-24 08:37:24 -06:00
Env.timeline.getter.userEntries(me.id) map { html.timeline.entries(_) }
}
2013-05-28 16:44:49 -06:00
2014-02-17 02:12:19 -07:00
def timelineMore = Auth { implicit ctx =>
me =>
2013-05-28 16:44:49 -06:00
Env.timeline.getter.moreUserEntries(me.id) map { html.timeline.more(_) }
}
2013-03-18 17:36:22 -06:00
}