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._
|
2014-12-18 18:35:55 -07:00
|
|
|
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 =>
|
2014-12-26 03:09:52 -07:00
|
|
|
negotiate(
|
2015-06-19 09:36:31 -06:00
|
|
|
html = renderHome(Results.Ok).map(NoCache),
|
2014-12-26 03:09:52 -07:00
|
|
|
api = _ => fuccess {
|
|
|
|
Ok(Json.obj(
|
|
|
|
"lobby" -> Json.obj(
|
|
|
|
"version" -> Env.lobby.history.version)
|
|
|
|
))
|
|
|
|
}
|
|
|
|
)
|
2013-05-08 15:34:37 -06:00
|
|
|
}
|
2013-03-20 10:34:38 -06:00
|
|
|
|
2014-06-01 17:01:39 -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) }
|
2013-03-20 10:34:38 -06:00
|
|
|
|
2014-06-01 17:01:39 -06:00
|
|
|
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,
|
2015-04-22 16:22:54 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-22 06:39:17 -07:00
|
|
|
def socket(apiVersion: Int) = SocketOption[JsValue] { implicit ctx =>
|
2014-02-17 02:12:19 -07:00
|
|
|
get("sri") ?? { uid =>
|
2016-03-02 16:29:22 -07:00
|
|
|
Env.lobby.socketHandler(uid = uid, ip = ctx.req.remoteAddress, user = ctx.me) 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 =>
|
2015-04-06 14:40:45 -06:00
|
|
|
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
|
|
|
}
|