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 {
case None => Ok(html.setup.friend(form, none, none, validFen)).fuccess
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))
}
}

View File

@ -1,6 +1,9 @@
@(denied: lila.challenge.ChallengeDenied)(implicit ctx: Context)
@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 {
case Reason.YouAreAnon => "Please register to send challenges"
case Reason.YouAreBlocked => s"You cannot challenge ${d.dest.titleUsername}"
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.FriendsOnly => s"${d.dest.titleUsername} only accepts challenges from friends"
case Reason.YouAreAnon => "Please register to send challenges."
case Reason.YouAreBlocked => s"You cannot challenge ${d.dest.titleUsername}."
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.FriendsOnly => s"${d.dest.titleUsername} only accepts challenges from friends."
}
}

View File

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