provide chat lines to mobile API
This commit is contained in:
parent
435d227e3c
commit
add4809404
|
@ -70,9 +70,13 @@ object Round extends LilaController with TheftPrevention {
|
||||||
},
|
},
|
||||||
Redirect(routes.Setup.await(fullId)).fuccess
|
Redirect(routes.Setup.await(fullId)).fuccess
|
||||||
),
|
),
|
||||||
api = apiVersion => Env.round version pov.gameId map { v =>
|
api = apiVersion => (Env.round version pov.gameId) zip
|
||||||
Ok(Env.round.jsonView.playerJson(pov, v, ctx.pref, apiVersion))
|
(pov.game.hasChat optionFu {
|
||||||
}
|
Env.chat.api.playerChat find pov.gameId map (_ forUser ctx.me)
|
||||||
|
}) map {
|
||||||
|
case (v, chat) =>
|
||||||
|
Ok(Env.round.jsonView.playerJson(pov, v, ctx.pref, chat, apiVersion))
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ object Setup extends LilaController with TheftPrevention with play.api.http.Cont
|
||||||
case (pov, call) => negotiate(
|
case (pov, call) => negotiate(
|
||||||
html = fuccess(redirectPov(pov, call)),
|
html = fuccess(redirectPov(pov, call)),
|
||||||
api = apiVersion => Env.round version pov.gameId map { v =>
|
api = apiVersion => Env.round version pov.gameId map { v =>
|
||||||
Created(Env.round.jsonView.playerJson(pov, v, ctx.pref, apiVersion)) as JSON
|
Created(Env.round.jsonView.playerJson(pov, v, ctx.pref, chat = none, apiVersion)) as JSON
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,69 +13,7 @@ http --form POST en.l.org/setup/ai variant=1 clock=false time=60 increment=60 le
|
||||||
Response: `201 CREATED`
|
Response: `201 CREATED`
|
||||||
```javascript
|
```javascript
|
||||||
{
|
{
|
||||||
"game": {
|
// see document format in the play.md doc file
|
||||||
"id": "39b12Ikl",
|
|
||||||
"variant": "chess960", // standard/chess960/fromPosition/kingOfTheHill/threeCheck
|
|
||||||
"speed": "blitz", // bullet|blitz|classical|unlimited
|
|
||||||
"perf": "chess960", // bullet|blitz|classical|chess960|kingOfTheHill|threeCheck
|
|
||||||
"rated": true,
|
|
||||||
"clock": false,
|
|
||||||
"clockRunning": false,
|
|
||||||
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
|
||||||
"finished": false,
|
|
||||||
"lastMove": null,
|
|
||||||
"moves": "",
|
|
||||||
"player": "white",
|
|
||||||
"started": true,
|
|
||||||
"startedAtTurn": 0,
|
|
||||||
"turns": 0
|
|
||||||
},
|
|
||||||
"clock": {
|
|
||||||
// all durations are expressed in seconds
|
|
||||||
"initial": 300, // initial time of the clock, here 5 minutes
|
|
||||||
"increment": 8, // fisher increment
|
|
||||||
"black": 36.0, // current time left for black
|
|
||||||
"white": 78.0, // current time left for white
|
|
||||||
"emerg": 30 // critical threshold
|
|
||||||
},
|
|
||||||
"player": {
|
|
||||||
"color": "white",
|
|
||||||
"id": "ErMy",
|
|
||||||
"spectator": false,
|
|
||||||
"version": 0
|
|
||||||
},
|
|
||||||
"opponent": {
|
|
||||||
"color": "black",
|
|
||||||
"ai": false,
|
|
||||||
"user_id": "ozzie" // request more info at /api/user/ozzie
|
|
||||||
},
|
|
||||||
"possibleMoves": { // list of moves you can play. Empty if not your turn to play.
|
|
||||||
"a2": "a3a4", // from a2, you can go on a3 or a4.
|
|
||||||
"b1": "a3c3",
|
|
||||||
"b2": "b3b4",
|
|
||||||
"c2": "c3c4",
|
|
||||||
"d2": "d3d4",
|
|
||||||
"e2": "e3e4",
|
|
||||||
"f2": "f3f4",
|
|
||||||
"g1": "f3h3",
|
|
||||||
"g2": "g3g4",
|
|
||||||
"h2": "h3h4"
|
|
||||||
},
|
|
||||||
"pref": {
|
|
||||||
"animationDelay": 240,
|
|
||||||
"autoQueen": 2,
|
|
||||||
"autoThreefold": 2,
|
|
||||||
"clockBar": true,
|
|
||||||
"clockTenths": true,
|
|
||||||
"enablePremove": true
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"pov": "/39b12IklErMy",
|
|
||||||
"end": "/39b12IklErMy/end",
|
|
||||||
"socket": "/39b12IklErMy/socket/v1",
|
|
||||||
"table": "/39b12IklErMy/table"
|
|
||||||
},
|
|
||||||
"tournamentId": null
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,18 @@ Response: `200 OK`
|
||||||
"socket": "/39b12IklErMy/socket/v1",
|
"socket": "/39b12IklErMy/socket/v1",
|
||||||
"table": "/39b12IklErMy/table"
|
"table": "/39b12IklErMy/table"
|
||||||
},
|
},
|
||||||
|
"chat": {
|
||||||
|
"lines": [
|
||||||
|
{
|
||||||
|
"u": "legend",
|
||||||
|
"t": "Hi there, I'm logged in, my name is legend"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"c": "black",
|
||||||
|
"t": "Hello! I'm anonymous, playing with the black pieces"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"tournamentId": null
|
"tournamentId": null
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -3,18 +3,18 @@ package lila.round
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import scala.math.{ min, max, round }
|
import scala.math.{ min, max, round }
|
||||||
|
|
||||||
import play.api.libs.json.Json
|
import play.api.libs.json._
|
||||||
|
|
||||||
|
import lila.common.PimpedJson._
|
||||||
import lila.game.{ Pov, Game, PerfPicker }
|
import lila.game.{ Pov, Game, PerfPicker }
|
||||||
import lila.pref.Pref
|
import lila.pref.Pref
|
||||||
import lila.common.PimpedJson._
|
|
||||||
|
|
||||||
import chess.format.Forsyth
|
import chess.format.Forsyth
|
||||||
import chess.{ Color, Clock }
|
import chess.{ Color, Clock }
|
||||||
|
|
||||||
final class JsonView(baseAnimationDelay: Duration) {
|
final class JsonView(baseAnimationDelay: Duration) {
|
||||||
|
|
||||||
def playerJson(pov: Pov, version: Int, pref: Pref, apiVersion: Int) = {
|
def playerJson(pov: Pov, version: Int, pref: Pref, chat: Option[lila.chat.MixedChat], apiVersion: Int) = {
|
||||||
import pov._
|
import pov._
|
||||||
Json.obj(
|
Json.obj(
|
||||||
"game" -> Json.obj(
|
"game" -> Json.obj(
|
||||||
|
@ -65,6 +65,16 @@ final class JsonView(baseAnimationDelay: Duration) {
|
||||||
"clockBar" -> pref.clockBar,
|
"clockBar" -> pref.clockBar,
|
||||||
"enablePremove" -> pref.premove
|
"enablePremove" -> pref.premove
|
||||||
),
|
),
|
||||||
|
"chat" -> chat.map { c =>
|
||||||
|
JsArray(c.lines map {
|
||||||
|
case lila.chat.UserLine(username, text, _) => Json.obj(
|
||||||
|
"u" -> username,
|
||||||
|
"t" -> text)
|
||||||
|
case lila.chat.PlayerLine(color, text) => Json.obj(
|
||||||
|
"c" -> color.name,
|
||||||
|
"t" -> text)
|
||||||
|
})
|
||||||
|
},
|
||||||
"possibleMoves" -> possibleMoves(pov),
|
"possibleMoves" -> possibleMoves(pov),
|
||||||
"tournamentId" -> game.tournamentId,
|
"tournamentId" -> game.tournamentId,
|
||||||
"poolId" -> game.poolId
|
"poolId" -> game.poolId
|
||||||
|
|
|
@ -13,7 +13,7 @@ trait RoundHelper {
|
||||||
def moretimeSeconds = roundEnv.moretimeSeconds
|
def moretimeSeconds = roundEnv.moretimeSeconds
|
||||||
|
|
||||||
def roundPlayerJsData(pov: Pov, version: Int, pref: Pref, apiVersion: Int) =
|
def roundPlayerJsData(pov: Pov, version: Int, pref: Pref, apiVersion: Int) =
|
||||||
roundEnv.jsonView.playerJson(pov, version, pref, apiVersion)
|
roundEnv.jsonView.playerJson(pov, version, pref, chat = none, apiVersion = apiVersion)
|
||||||
|
|
||||||
def roundWatcherJsData(pov: Pov, version: Int, tv: Boolean, pref: Pref) =
|
def roundWatcherJsData(pov: Pov, version: Int, tv: Boolean, pref: Pref) =
|
||||||
roundEnv.jsonView.watcherJson(pov, version, tv, pref)
|
roundEnv.jsonView.watcherJson(pov, version, tv, pref)
|
||||||
|
|
Loading…
Reference in a new issue