Add study chat data to mobile api

This commit is contained in:
Vincent Velociter 2018-05-09 09:47:12 +02:00
parent 0564d0289e
commit a4107d94fc
2 changed files with 18 additions and 4 deletions

View file

@ -148,10 +148,19 @@ object Study extends LilaController {
sVersion <- env.version(sc.study.id)
streams <- streamsOf(sc.study)
} yield Ok(html.study.show(sc.study, data, chat, sVersion, streams)),
api = _ => Ok(Json.obj(
"study" -> data.study,
"analysis" -> data.analysis
)).fuccess
api = _ => chatOf(sc.study).map { chatOpt =>
Ok(
Json.obj(
"study" -> data.study.add("chat" -> chatOpt.map { c =>
lila.chat.JsonView.mobile(
chat = c.chat,
writeable = ctx.userId.??(sc.study.canChat)
)
}),
"analysis" -> data.analysis
)
)
}
)
} yield res
}

View file

@ -18,6 +18,11 @@ object JsonView {
"history" -> u.history
)
def mobile(chat: AnyChat, writeable: Boolean = true) = Json.obj(
"lines" -> apply(chat),
"writeable" -> writeable
)
implicit val chatIdWrites: Writes[Chat.Id] = stringIsoWriter(Chat.chatIdIso)
lazy val timeoutReasons = Json toJson ChatTimeout.Reason.all