lila/app/controllers/Lobby.scala

59 lines
1.6 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(
2015-06-19 09:36:31 -06:00
html = renderHome(Results.Ok).map(NoCache),
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),
2015-06-18 06:15:07 -06:00
tours = Env.tournament.cached promotable true,
simuls = Env.simul allCreatedFeaturable true
2016-02-07 01:19:21 -07:00
) map (html.lobby.home.apply _).tupled map { status(_) } map ensureSessionId(ctx.req)
2013-05-08 15:34:37 -06:00
2014-12-17 17:02:59 -07:00
def seeks = Open { implicit ctx =>
2014-12-28 16:15:42 -07:00
negotiate(
html = fuccess(NotFound),
api = _ => ctx.me.fold(Env.lobby.seekApi.forAnon)(Env.lobby.seekApi.forUser) map { seeks =>
Ok(JsArray(seeks.map(_.render)))
}
)
2014-12-17 17:02:59 -07:00
}
def socket(apiVersion: Int) = SocketOption[JsValue] { implicit ctx =>
2014-02-17 02:12:19 -07:00
get("sri") ?? { uid =>
Env.lobby.socketHandler(
uid = uid,
ip = ctx.req.remoteAddress,
user = ctx.me,
mobile = getBool("mobile")) map some
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 =>
Env.timeline.entryRepo.userEntries(me.id) map { html.timeline.entries(_) }
2013-05-24 08:37:24 -06:00
}
2013-03-18 17:36:22 -06:00
}