better grant challenges, based on prefs, relations, ratings

challenge-granter
Thibault Duplessis 2017-06-05 20:27:15 +02:00
parent 522add2a0a
commit d1f981bee1
4 changed files with 16 additions and 9 deletions

View File

@ -49,7 +49,7 @@ object Setup extends LilaController with TheftPrevention {
userId ?? UserRepo.named flatMap { userId ?? UserRepo.named flatMap {
case None => Ok(html.setup.friend(form, none, none, validFen)).fuccess case None => Ok(html.setup.friend(form, none, none, validFen)).fuccess
case Some(user) => Env.challenge.granter(ctx.me, user, none) map { case Some(user) => Env.challenge.granter(ctx.me, user, none) map {
case Some(denied) => BadRequest(html.challenge.denied(denied)) case Some(denied) => BadRequest(lila.challenge.ChallengeDenied.inEnglish(denied))
case None => Ok(html.setup.friend(form, user.some, none, validFen)) case None => Ok(html.setup.friend(form, user.some, none, validFen))
} }
} }

View File

@ -1,6 +1,9 @@
@(denied: lila.challenge.ChallengeDenied)(implicit ctx: Context) @(denied: lila.challenge.ChallengeDenied)(implicit ctx: Context)
@site.message( @site.message(
title = lila.challenge.ChallengeDenied.inEnglish(denied)) { icon = Html("j").some,
title = trans.challengeToPlay.txt()) {
<p>@lila.challenge.ChallengeDenied.inEnglish(denied)</p>
} }

View File

@ -20,11 +20,11 @@ object ChallengeDenied {
} }
def inEnglish(d: ChallengeDenied) = d.reason match { def inEnglish(d: ChallengeDenied) = d.reason match {
case Reason.YouAreAnon => "Please register to send challenges" case Reason.YouAreAnon => "Please register to send challenges."
case Reason.YouAreBlocked => s"You cannot challenge ${d.dest.titleUsername}" case Reason.YouAreBlocked => s"You cannot challenge ${d.dest.titleUsername}."
case Reason.TheyDontAcceptChallenges => s"${d.dest.titleUsername} does not accept any challenge" case Reason.TheyDontAcceptChallenges => s"${d.dest.titleUsername} does not accept any challenge."
case Reason.RatingOutsideRange(perf) => s"Your ${perf.name} rating is too far from ${d.dest.titleUsername} rating" case Reason.RatingOutsideRange(perf) => s"Your ${perf.name} rating is too far from ${d.dest.titleUsername} rating."
case Reason.FriendsOnly => s"${d.dest.titleUsername} only accepts challenges from friends" case Reason.FriendsOnly => s"${d.dest.titleUsername} only accepts challenges from friends."
} }
} }

View File

@ -442,8 +442,12 @@ module.exports = function(cfg, element) {
prepareForm(); prepareForm();
lichess.pubsub.emit('content_loaded')(); lichess.pubsub.emit('content_loaded')();
}, },
error: function() { error: function(res) {
lichess.reload(); if (res.status == 400) {
$startButtons.find('a.active').removeClass('active');
alert(res.responseText);
}
else lichess.reload();
} }
}); });
$(this).addClass('active').siblings().removeClass('active'); $(this).addClass('active').siblings().removeClass('active');