add API endpoint to post private messages
parent
f74825cbd0
commit
73047c2aca
|
@ -608,6 +608,9 @@ abstract private[controllers] class LilaController(val env: Env)
|
|||
protected def jsonFormErrorDefaultLang(err: Form[_]) =
|
||||
jsonFormError(err)(lila.i18n.defaultLang)
|
||||
|
||||
protected def jsonFormErrorFor(err: Form[_], req: RequestHeader, user: Option[UserModel]) =
|
||||
jsonFormError(err)(lila.i18n.I18nLangPicker(req, user))
|
||||
|
||||
protected def pageHit(req: RequestHeader): Unit =
|
||||
if (HTTPRequest isHuman req) lila.mon.http.path(req.path).increment()
|
||||
|
||||
|
|
|
@ -74,11 +74,22 @@ final class Msg(
|
|||
)
|
||||
}
|
||||
|
||||
def compatAnswer(userId: String) = AuthBody { implicit ctx => me =>
|
||||
def apiPost(username: String) = AuthOrScopedBody(_.Msg.Write)(
|
||||
// compat
|
||||
auth = ctx => me => doApiPost(me, username)(ctx.body),
|
||||
// new API
|
||||
scoped = req => me => doApiPost(me, username)(req)
|
||||
)
|
||||
|
||||
private def doApiPost(
|
||||
me: lila.user.User,
|
||||
username: String
|
||||
)(implicit req: play.api.mvc.Request[_]) = {
|
||||
val userId = lila.user.User normalize username
|
||||
env.msg.compat
|
||||
.reply(me, userId)(ctx.body)
|
||||
.reply(me, userId)
|
||||
.fold(
|
||||
jsonFormError,
|
||||
err => jsonFormErrorFor(err, req, me.some),
|
||||
_ inject Ok(Json.obj("ok" -> true, "id" -> userId))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -430,9 +430,10 @@ GET /inbox/search controllers.Msg.search(q: String)
|
|||
GET /inbox/unread-count controllers.Msg.unreadCount
|
||||
GET /inbox/:username controllers.Msg.threadWith(username: String)
|
||||
DELETE /inbox/:username controllers.Msg.threadDelete(username: String)
|
||||
# Msg API/compat
|
||||
POST /inbox/:username controllers.Msg.apiPost(username: String)
|
||||
# Msg compat
|
||||
POST /inbox/new controllers.Msg.compatCreate
|
||||
POST /inbox/:userId controllers.Msg.compatAnswer(userId: String)
|
||||
|
||||
# Coach
|
||||
GET /coach controllers.Coach.allDefault(page: Int ?= 1)
|
||||
|
|
|
@ -37,6 +37,10 @@ object OAuthScope {
|
|||
case object Write extends OAuthScope("team:write", "Join, leave, and manage teams")
|
||||
}
|
||||
|
||||
object Msg {
|
||||
case object Write extends OAuthScope("msg:write", "Send private messages to other players")
|
||||
}
|
||||
|
||||
object Bot {
|
||||
case object Play extends OAuthScope("bot:play", "Play as a bot")
|
||||
}
|
||||
|
@ -56,6 +60,7 @@ object OAuthScope {
|
|||
Tournament.Write,
|
||||
Puzzle.Read,
|
||||
Team.Write,
|
||||
Msg.Write,
|
||||
Bot.Play
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue