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-03 08:22:50 -06:00
|
|
|
"kid" -> me.kid,
|
|
|
|
"coach" -> isGranted(_.Coach),
|
|
|
|
"prefs" -> prefs,
|
|
|
|
"i18n" -> translations
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|