lila/app/controllers/Lobby.scala

77 lines
2.2 KiB
Scala
Raw Normal View History

2013-03-18 17:36:22 -06:00
package controllers
2014-12-18 16:25:37 -07:00
import play.api.libs.json._
2013-05-24 08:37:24 -06:00
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, HTTPRequest }
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
2014-02-17 02:12:19 -07:00
def home = Open { implicit ctx =>
negotiate(
html = renderHome(Results.Ok).map(_.withHeaders(
CACHE_CONTROL -> "no-cache", PRAGMA -> "no-cache"
)),
api = _ => fuccess {
Ok(Json.obj(
"lobby" -> Json.obj(
"version" -> Env.lobby.history.version)
))
}
)
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-27 10:16:03 -07:00
) map (html.lobby.home.apply _).tupled map { template =>
// the session cookie is required for anon lobby filter storage
ctx.req.session.data.contains(LilaCookie.sessionId).fold(
status(template),
status(template) 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 =>
if (HTTPRequest isSynchronousHttp ctx.req)
fuccess(Redirect(routes.Lobby.home))
else lila.game.GameRepo nowPlaying me map { povs =>
html.lobby.playing(povs)
}
}
2014-12-17 17:02:59 -07:00
def seeks = Open { implicit ctx =>
2014-12-18 16:25:37 -07:00
ctx.me.fold(Env.lobby.seekApi.forAnon)(Env.lobby.seekApi.forUser) flatMap { seeks =>
negotiate(
html = if (HTTPRequest isSynchronousHttp ctx.req) fuccess(Redirect(routes.Lobby.home))
else fuccess(html.lobby.seeks(seeks)),
2014-12-28 10:50:30 -07:00
api = _ => fuccess(Ok(JsArray(seeks.map(_.render))))
2014-12-18 16:25:37 -07:00
)
2014-12-17 17:02:59 -07:00
}
}
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
}