/api/board/game/{id}/chat endpoint to fetch the game chat - for #9613

pull/9670/head
Thibault Duplessis 2021-08-27 14:00:52 +02:00
parent 4fcc2e7b2f
commit 3efbcbe28e
3 changed files with 21 additions and 2 deletions

View File

@ -66,7 +66,7 @@ final class PlayApi(
}
}
def boardCommand(cmd: String) =
def boardCommandPost(cmd: String) =
ScopedBody(_.Board.Play) { implicit req => me =>
impl.command(me, cmd)(WithPovAsBoard)
}
@ -119,6 +119,17 @@ final class PlayApi(
}
}
def boardCommandGet(cmd: String) =
ScopedBody(_.Board.Play) { implicit req => me =>
cmd.split('/') match {
case Array("game", id, "chat") =>
WithPovAsBoard(id, me) { pov =>
env.chat.api.userChat.find(lila.chat.Chat.Id(pov.game.id)) map
lila.chat.JsonView.boardApi map JsonOk
}
}
}
// utils
private def toResult(f: Funit): Fu[Result] = catchClientError(f inject jsonOkResult)

View File

@ -691,7 +691,8 @@ GET /api/bot/online controllers.PlayApi.botOnlineApi
GET /api/board/game/stream/:id controllers.PlayApi.boardGameStream(id: String)
POST /api/board/game/:id/move/:uci controllers.PlayApi.boardMove(id: String, uci: String, offeringDraw: Option[Boolean] ?= None)
POST /api/board/seek controllers.Setup.boardApiHook
POST /api/board/*cmd controllers.PlayApi.boardCommand(cmd: String)
POST /api/board/*cmd controllers.PlayApi.boardCommandPost(cmd: String)
GET /api/board/*cmd controllers.PlayApi.boardCommandGet(cmd: String)
# Account
GET /account/passwd controllers.Account.passwd

View File

@ -30,6 +30,13 @@ object JsonView {
"writeable" -> writeable
)
def boardApi(chat: UserChat) = JsArray {
chat.lines collect {
case UserLine(name, _, _, text, troll, del) if !troll && !del =>
Json.obj("text" -> text, "user" -> name)
}
}
object writers {
implicit val chatIdWrites: Writes[Chat.Id] = stringIsoWriter(Chat.chatIdIso)