fix challenge accept API endpoint when challenge was canceled
parent
3b5b7d4bb0
commit
7983f75234
|
@ -132,7 +132,10 @@ final class Challenge(
|
|||
_.filter(isForMe(_, me.some)) match {
|
||||
case None => tryRematch
|
||||
case Some(c) if c.accepted => tryRematch
|
||||
case Some(challenge) => api.accept(challenge, me.some, none) inject jsonOkResult
|
||||
case Some(c) =>
|
||||
api.accept(c, me.some, none) map {
|
||||
_.fold(BadRequest(_), _ => jsonOkResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ case class Challenge(
|
|||
def openDest = destUser.isEmpty
|
||||
def online = status == Status.Created
|
||||
def active = online || status == Status.Offline
|
||||
def canceled = status == Status.Canceled
|
||||
def declined = status == Status.Declined
|
||||
def accepted = status == Status.Accepted
|
||||
|
||||
|
|
|
@ -89,7 +89,8 @@ final class ChallengeApi(
|
|||
color: Option[chess.Color] = None
|
||||
): Fu[Validated[String, Option[Pov]]] =
|
||||
acceptQueue {
|
||||
if (user.exists(_.isBot) && !Game.isBotCompatible(chess.Speed(c.clock.map(_.config))))
|
||||
if (c.canceled) fuccess(Invalid("The challenge has been canceled."))
|
||||
else if (user.exists(_.isBot) && !Game.isBotCompatible(chess.Speed(c.clock.map(_.config))))
|
||||
fuccess(Invalid("Game incompatible with a BOT account"))
|
||||
else if (c.challengerIsOpen)
|
||||
repo.setChallenger(c.setChallenger(user, sid), color) inject Valid(none)
|
||||
|
|
Loading…
Reference in New Issue