From bd98f747d1cc0e9b04bfe32cf94dba74e4bc3b15 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 31 Dec 2014 01:46:14 +0100 Subject: [PATCH] don't play clock emergency sounds on simul - resolves #177 --- app/controllers/Round.scala | 6 +++--- app/controllers/Setup.scala | 4 ++-- modules/api/src/main/RoundApi.scala | 7 +++++-- ui/round/src/ctrl.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/Round.scala b/app/controllers/Round.scala index 233d700e48..0e2b377eb0 100644 --- a/app/controllers/Round.scala +++ b/app/controllers/Round.scala @@ -56,7 +56,7 @@ object Round extends LilaController with TheftPrevention { Env.game.crosstableApi(pov.game) zip otherPovs(pov.gameId) flatMap { case ((tour, crosstable), playing) => - Env.api.roundApi.player(pov, Env.api.version) map { data => + Env.api.roundApi.player(pov, Env.api.version, playing) map { data => Ok(html.round.player(pov, data, tour = tour, cross = crosstable, playing = playing)) } } @@ -64,7 +64,7 @@ object Round extends LilaController with TheftPrevention { Redirect(routes.Setup.await(fullId)).fuccess ) }, - api = apiVersion => Env.api.roundApi.player(pov, apiVersion) map { Ok(_) } + api = apiVersion => Env.api.roundApi.player(pov, apiVersion, Nil) map { Ok(_) } ) } } @@ -121,7 +121,7 @@ object Round extends LilaController with TheftPrevention { private def join(pov: Pov)(implicit ctx: Context): Fu[Result] = GameRepo initialFen pov.gameId zip - Env.api.roundApi.player(pov, Env.api.version) zip + Env.api.roundApi.player(pov, Env.api.version, otherPovs = Nil) zip ((pov.player.userId orElse pov.opponent.userId) ?? UserRepo.byId) map { case ((fen, data), opponent) => Ok(html.setup.join( pov, data, opponent, Env.setup.friendConfigMemo get pov.game.id, fen)) diff --git a/app/controllers/Setup.scala b/app/controllers/Setup.scala index 5d50528946..9a6e43a2d1 100644 --- a/app/controllers/Setup.scala +++ b/app/controllers/Setup.scala @@ -138,7 +138,7 @@ object Setup extends LilaController with TheftPrevention with play.api.http.Cont OptionFuResult(GameRepo pov fullId) { pov => pov.game.started.fold( Redirect(routes.Round.player(pov.fullId)).fuccess, - Env.api.roundApi.player(pov, Env.api.version) zip + Env.api.roundApi.player(pov, Env.api.version, otherPovs = Nil) zip (userId ?? UserRepo.named) flatMap { case (data, user) => PreventTheft(pov) { Ok(html.setup.await( @@ -185,7 +185,7 @@ object Setup extends LilaController with TheftPrevention with play.api.http.Cont config => op(config)(ctx) flatMap { case (pov, call) => negotiate( html = fuccess(redirectPov(pov, call)), - api = apiVersion => Env.api.roundApi.player(pov, apiVersion) map { data => + api = apiVersion => Env.api.roundApi.player(pov, apiVersion, otherPovs = Nil) map { data => Created(data) as JSON } ) diff --git a/modules/api/src/main/RoundApi.scala b/modules/api/src/main/RoundApi.scala index b92bd641f9..26020f368a 100644 --- a/modules/api/src/main/RoundApi.scala +++ b/modules/api/src/main/RoundApi.scala @@ -18,13 +18,13 @@ private[api] final class RoundApi( analysisApi: AnalysisApi, lightUser: String => Option[LightUser]) { - def player(pov: Pov, apiVersion: Int)(implicit ctx: Context): Fu[JsObject] = + def player(pov: Pov, apiVersion: Int, otherPovs: List[Pov])(implicit ctx: Context): Fu[JsObject] = jsonView.playerJson(pov, ctx.pref, apiVersion, ctx.me, withBlurs = ctx.me ?? Granter(_.ViewBlurs)) zip (pov.game.tournamentId ?? TournamentRepo.byId) zip (ctx.me ?? (me => noteApi.get(pov.gameId, me.id))) map { case ((json, tourOption), note) => ( - blindMode _ compose withTournament(tourOption)_ compose withNote(note)_ + blindMode _ compose withTournament(tourOption)_ compose withNote(note)_ compose withOtherPovs(otherPovs)_ )(json) } @@ -40,6 +40,9 @@ private[api] final class RoundApi( )(json) } + private def withOtherPovs(otherPovs: List[Pov])(json: JsObject) = + if (otherPovs.isEmpty) json else json + ("simul" -> JsBoolean(true)) + private def withNote(note: String)(json: JsObject) = if (note.isEmpty) json else json + ("note" -> JsString(note)) diff --git a/ui/round/src/ctrl.js b/ui/round/src/ctrl.js index 5a3ef4bf72..001de68713 100644 --- a/ui/round/src/ctrl.js +++ b/ui/round/src/ctrl.js @@ -83,7 +83,7 @@ module.exports = function(opts) { this.clock = this.data.clock ? new clockCtrl( this.data.clock, - throttle(partial(this.socket.send, 'outoftime'), this.data.player.spectator ? 1000 : 500), (this.data.player.spectator || !this.data.pref.clockSound) ? null : this.data.player.color + throttle(partial(this.socket.send, 'outoftime'), this.data.player.spectator ? 1000 : 500), (this.data.simul || this.data.player.spectator || !this.data.pref.clockSound) ? null : this.data.player.color ) : false; this.isClockRunning = function() {