diff --git a/modules/challenge/src/main/Challenger.scala b/modules/challenge/src/main/Challenger.scala deleted file mode 100644 index a0f4fedc34..0000000000 --- a/modules/challenge/src/main/Challenger.scala +++ /dev/null @@ -1,48 +0,0 @@ -// package lila.challenge - -// import akka.actor._ -// import akka.pattern.{ ask, pipe } -// import play.api.libs.json.Json -// import play.twirl.api.Html - -// import lila.hub.actorApi.map.Tell -// import lila.hub.actorApi.SendTo -// import lila.hub.actorApi.challenge._ -// import lila.user.UserRepo -// import makeTimeout.short - -// private[challenge] final class Challenger( -// roundHub: ActorSelection, -// renderer: ActorSelection, -// prefApi: lila.pref.PrefApi, -// relationApi: lila.relation.RelationApi) extends Actor { - -// private val bus = context.system.lilaBus - -// def receive = { - -// case msg@RemindChallenge(gameId, from, to) => -// UserRepo.named(from) zip UserRepo.named(to) zip (renderer ? msg) flatMap { -// case ((Some(fromU), Some(toU)), html: Html) => -// prefApi.getPref(toU) zip relationApi.fetchFollows(toU.id, fromU.id) flatMap { -// case (pref, follows) => -// lila.pref.Pref.Challenge.block(fromU, toU, pref.challenge, follows, -// fromCheat = fromU.engine && !toU.engine) match { -// case None => fuccess { -// bus.publish(SendTo(to, Json.obj( -// "t" -> "challengeReminder", -// "d" -> Json.obj( -// "id" -> gameId, -// "html" -> html.toString -// ) -// )), 'users) -// } -// case Some(err) => fufail(err) -// } -// } -// case _ => funit -// } - -// case msg@DeclineChallenge(gameId) => roundHub ! Tell(gameId, msg) -// } -// } diff --git a/public/javascripts/big.js b/public/javascripts/big.js index f43e02c380..1e928413f0 100644 --- a/public/javascripts/big.js +++ b/public/javascripts/big.js @@ -353,14 +353,13 @@ lichess.challengeApp = (function() { var element = document.getElementById('challenge_app'); instance = LichessChallenge(element, { data: data, + show: function() { + if (!$(element).is(':visible')) $toggle.click(); + }, setCount: function(nb) { $toggle.attr('data-count', nb); } }); - if (!lichess.quietMode) { - if (!$(element).is(':visible')) $toggle.click(); - $.sound.newChallenge(); - } }); }; return { @@ -1129,7 +1128,7 @@ lichess.unique = function(xs) { }); $('#challenge_notifications_tag').one('mouseover click', function() { lichess.challengeApp.load(); - }); //.trigger('click'); + }).trigger('click'); $('#translation_call .close').click(function() { $.post($(this).data("href")); diff --git a/public/stylesheets/challengeApp.css b/public/stylesheets/challengeApp.css index b1b4a1f9d2..bc570eaa4a 100644 --- a/public/stylesheets/challengeApp.css +++ b/public/stylesheets/challengeApp.css @@ -11,7 +11,6 @@ margin-top: 5px; position: relative; height: 76px; - cursor: pointer; transition: 0.13s; background: #fff; box-shadow: 0 1px 7px rgba(0, 0, 0, 0.3); @@ -31,11 +30,13 @@ width: 100%; transition: 0.13s; } -#challenge_app .challenge form { +#challenge_app .challenge .buttons > * { display: inline-block; width: 50%; + text-align: center; } #challenge_app .challenge button { + cursor: pointer; color: #759900; width: 100%; display: block; diff --git a/ui/challenge/src/ctrl.js b/ui/challenge/src/ctrl.js index 2476de2315..ab5b410f71 100644 --- a/ui/challenge/src/ctrl.js +++ b/ui/challenge/src/ctrl.js @@ -20,14 +20,26 @@ module.exports = function(env) { } this.update = function(data) { - console.log(data, 'update'); this.data = data; this.vm.initiating = false; this.vm.reloading = false; env.setCount(this.countActiveIn()); + this.notifyNew(); m.redraw(); }.bind(this); + this.notifyNew = function() { + this.data.in.forEach(function(c) { + if (lichess.once('challenge-' + c.id)) { + if (!lichess.quietMode) { + env.show(); + $.sound.newChallenge(); + } + lichess.desktopNotification(showUser(c.challenger) + ' challenges you!'); + } + }); + }.bind(this); + this.decline = function(id) { this.data.in.forEach(function(c) { if (c.id === id) { @@ -39,5 +51,11 @@ module.exports = function(env) { xhr.load().then(this.update); + var showUser = function(user) { + var rating = u.rating + (u.provisional ? '?' : ''); + var fullName = (u.title ? u.title + ' ' : '') + u.name; + return fullName + ' (' + rating + ')'; + }; + this.trans = lichess.trans(env.i18n); }; diff --git a/ui/challenge/src/view.js b/ui/challenge/src/view.js index df4d080372..53b34ad961 100644 --- a/ui/challenge/src/view.js +++ b/ui/challenge/src/view.js @@ -27,41 +27,59 @@ function timeControl(c) { } } +function inButtons(ctrl, c) { + return [ + m('form', { + method: 'post', + action: '/challenge/' + c.id + '/accept' + }, m('button', { + 'type': 'submit', + class: 'submit button accept', + 'data-icon': 'E' + })), + m('form', m('button', { + 'type': 'submit', + class: 'submit button decline', + 'data-icon': 'L', + onclick: function(e) { + ctrl.decline(c.id); + return false; + } + })) + ]; +} + +function outButtons(ctrl, c) { + return [ + m('div.text', 'waiting...'), + m('form', { + method: 'post', + action: '/challenge/' + c.id + '/cancel' + }, m('button', { + 'type': 'submit', + class: 'submit button decline', + 'data-icon': 'L', + })), + ]; +} + function challenge(ctrl, dir) { return function(c) { return m('div', { - class: 'challenge' + (c.declined ? ' declined' : ''), + class: 'challenge' + ' ' + dir + (c.declined ? ' declined' : ''), }, [ m('i', { 'data-icon': c.perf.icon }), m('div.content', [ - m('span.title', user(c.challenger)), + m('span.title', user(dir === 'in' ? c.challenger : c.destUser)), m('span.desc', [ c.rated ? 'Rated' : 'Casual', timeControl(c.timeControl), c.variant.name ].join(' ')) ]), - m('div.buttons', [ - m('form', { - method: 'post', - action: '/challenge/' + c.id + '/accept' - }, m('button', { - 'type': 'submit', - class: 'submit button accept', - 'data-icon': 'E' - })), - m('form', m('button', { - 'type': 'submit', - class: 'submit button decline', - 'data-icon': 'L', - onclick: function(e) { - ctrl.decline(c.id); - return false; - } - })) - ]) + m('div.buttons', (dir === 'in' ? inButtons : outButtons)(ctrl, c)) ]); }; }