lila/app/controllers/Lobby.scala
Thibault Duplessis 6c1f73887c Merge branch 'master' into tourneyScheduleUI
* master:
  hy "Հայերեն" translation #14527. Author: Firebrass11. Added 'Three checks'
  ro "Română" translation #14526. Author: vladg. Filled missing translations
  disable move confirmation for anonymous players
  extra berserk rule in tournament FAQ - closes #595
  experimental marathon trophy
  try harder to capture rematches on TV
  open wikipedia in a new tab
  link thematic tournament position on wikipedia
  opening thematic tournaments every 6 hours
  only feature interesting openings in thematic tournaments
  some things are not meant to be cached
2015-06-20 11:14:41 +02:00

66 lines
1.9 KiB
Scala

package controllers
import play.api.libs.json._
import play.api.mvc._
import lila.api.Context
import lila.app._
import lila.common.{ LilaCookie, HTTPRequest }
import views._
object Lobby extends LilaController {
def home = Open { implicit ctx =>
negotiate(
html = renderHome(Results.Ok).map(NoCache),
api = _ => fuccess {
Ok(Json.obj(
"lobby" -> Json.obj(
"version" -> Env.lobby.history.version)
))
}
)
}
def handleStatus(req: RequestHeader, status: Results.Status): Fu[Result] =
reqToCtx(req) flatMap { ctx => renderHome(status)(ctx) }
def renderHome(status: Results.Status)(implicit ctx: Context): Fu[Result] =
Env.current.preloader(
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds),
tours = Env.tournament.cached promotable true,
simuls = Env.simul allCreatedFeaturable true
) 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)
)
}
def seeks = Open { implicit ctx =>
negotiate(
html = fuccess(NotFound),
api = _ => ctx.me.fold(Env.lobby.seekApi.forAnon)(Env.lobby.seekApi.forUser) map { seeks =>
Ok(JsArray(seeks.map(_.render)))
}
)
}
def socket(apiVersion: Int) = SocketOption[JsValue] { implicit ctx =>
get("sri") ?? { uid =>
Env.lobby.socketHandler(uid = uid, user = ctx.me) map some
}
}
def timeline = Auth { implicit ctx =>
me =>
Env.timeline.entryRepo.userEntries(me.id) map { html.timeline.entries(_) }
}
def timelineMore = Auth { implicit ctx =>
me =>
Env.timeline.entryRepo.moreUserEntries(me.id) map { html.timeline.more(_) }
}
}