2017-05-03 08:22:50 -06:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import play.api.mvc._
|
2017-05-03 12:50:35 -06:00
|
|
|
import scala.collection.breakOut
|
2017-05-03 08:22:50 -06:00
|
|
|
|
|
|
|
import lila.api.Context
|
|
|
|
import lila.app._
|
|
|
|
import lila.pref.JsonView._
|
|
|
|
import play.api.libs.json._
|
|
|
|
|
|
|
|
object Dasher extends LilaController {
|
|
|
|
|
|
|
|
private def translations(implicit ctx: Context) = Env.i18n.jsDump.keysToObject(List(
|
|
|
|
Env.i18n.keys.profile,
|
|
|
|
Env.i18n.keys.inbox,
|
|
|
|
Env.i18n.keys.preferences,
|
|
|
|
Env.i18n.keys.logOut,
|
|
|
|
Env.i18n.keys.networkLagBetweenYouAndLichess,
|
2017-05-03 13:53:14 -06:00
|
|
|
Env.i18n.keys.timeToProcessAMoveOnLichessServer,
|
|
|
|
Env.i18n.keys.sound
|
2017-05-03 08:22:50 -06:00
|
|
|
), Env.i18n.pool lang ctx.req)
|
|
|
|
|
|
|
|
def get = Open { implicit ctx =>
|
|
|
|
negotiate(
|
|
|
|
html = notFound,
|
|
|
|
api = _ => ctx.me match {
|
|
|
|
case None => fuccess(unauthorizedApiResult)
|
|
|
|
case Some(me) => Env.pref.api.getPref(me) map { prefs =>
|
|
|
|
Ok {
|
2017-05-03 12:50:35 -06:00
|
|
|
Json.obj(
|
|
|
|
"user" -> lila.common.LightUser.lightUserWrites.writes(me.light),
|
2017-05-03 10:10:11 -06:00
|
|
|
"lang" -> Json.obj(
|
|
|
|
"current" -> Env.i18n.pool.lang(ctx.req).language.toString,
|
|
|
|
"accepted" -> (ctx.req.acceptLanguages.map(_.language.toString)(breakOut): List[String]).distinct
|
|
|
|
),
|
2017-05-03 13:53:14 -06:00
|
|
|
"sound" -> Json.obj(
|
|
|
|
"list" -> lila.pref.SoundSet.list.map { set =>
|
|
|
|
s"${set.key} ${set.name}"
|
|
|
|
}
|
|
|
|
),
|
2017-05-04 06:32:10 -06:00
|
|
|
"background" -> Json.obj(
|
|
|
|
"current" -> ctx.currentBg,
|
|
|
|
"image" -> ctx.bgImg
|
|
|
|
),
|
2017-05-04 07:33:50 -06:00
|
|
|
"board" -> Json.obj(
|
|
|
|
"is3d" -> ctx.is3d,
|
|
|
|
"zoom" -> ctx.zoom
|
|
|
|
),
|
2017-05-04 10:51:28 -06:00
|
|
|
"theme" -> Json.obj(
|
|
|
|
"d2" -> Json.obj(
|
|
|
|
"current" -> ctx.currentTheme.name,
|
|
|
|
"list" -> lila.pref.Theme.list.map(_.name)
|
|
|
|
),
|
|
|
|
"d3" -> Json.obj(
|
|
|
|
"current" -> ctx.currentTheme3d.name,
|
|
|
|
"list" -> lila.pref.Theme3d.list.map(_.name)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
"piece" -> Json.obj(
|
|
|
|
"d2" -> ctx.currentPieceSet.name,
|
|
|
|
"d3" -> ctx.currentPieceSet3d.name
|
|
|
|
),
|
2017-05-03 08:22:50 -06:00
|
|
|
"kid" -> me.kid,
|
|
|
|
"coach" -> isGranted(_.Coach),
|
|
|
|
"prefs" -> prefs,
|
|
|
|
"i18n" -> translations
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|