From 212a1a569abb3ea08bc0e876cd158850ac604619 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Tue, 6 May 2014 21:58:41 +0200 Subject: [PATCH] custom code for ChessWhiz because he's pretty awesome --- app/views/lobby/home.scala.html | 2 +- modules/tv/src/main/Env.scala | 3 +++ modules/tv/src/main/Streaming.scala | 11 ++++++----- project/Build.scala | 2 +- public/stylesheets/common.css | 7 +++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/views/lobby/home.scala.html b/app/views/lobby/home.scala.html index 3701a070b5..9ed7126904 100644 --- a/app/views/lobby/home.scala.html +++ b/app/views/lobby/home.scala.html @@ -32,7 +32,7 @@ } @streams.map { s => - @s.name + LIVE! @s.name }
@timeline.entries(userTimeline) diff --git a/modules/tv/src/main/Env.scala b/modules/tv/src/main/Env.scala index 60f6254a93..e58e19a34d 100644 --- a/modules/tv/src/main/Env.scala +++ b/modules/tv/src/main/Env.scala @@ -7,6 +7,7 @@ import lila.common.PimpedConfig._ final class Env( config: Config, hub: lila.hub.Env, + isOnline: String => Boolean, system: akka.actor.ActorSystem, scheduler: lila.common.Scheduler) { @@ -22,6 +23,7 @@ final class Env( private lazy val streaming = new Streaming( system = system, + isOnline = isOnline, ustreamApiKey = UstreamApiKey) def streamsOnAir = streaming.onAir @@ -48,6 +50,7 @@ object Env { lazy val current = "[boot] tv" describes new Env( config = lila.common.PlayApp loadConfig "tv", hub = lila.hub.Env.current, + isOnline = lila.user.Env.current.isOnline, system = lila.common.PlayApp.system, scheduler = lila.common.PlayApp.scheduler) } diff --git a/modules/tv/src/main/Streaming.scala b/modules/tv/src/main/Streaming.scala index 30d2f80381..b98250efeb 100644 --- a/modules/tv/src/main/Streaming.scala +++ b/modules/tv/src/main/Streaming.scala @@ -6,7 +6,8 @@ import play.api.libs.ws.WS private final class Streaming( system: ActorSystem, - ustreamApiKey: String) { + ustreamApiKey: String, + isOnline: String => Boolean) { import Streaming._ import Twitch.Reads._ @@ -26,16 +27,16 @@ private final class Streaming( case Get => sender ! onAir case Search => - val keyword = "lichess.org" val max = 2 val twitch = WS.url("https://api.twitch.tv/kraken/search/streams") - .withQueryString("q" -> keyword) + .withQueryString("q" -> "lichess.org") .withHeaders("Accept" -> "application/vnd.twitchtv.v2+json") .get().map { _.json.asOpt[Twitch.Result] ?? (_.streamsOnAir take max) } - val ustream = WS.url(s"http://api.ustream.tv/json/stream/all/search/description:like:$keyword") + val chesswhiz = isOnline("chesswhiz") ?? + WS.url(s"http://api.ustream.tv/json/stream/recent/search/title:like:chesswhiz") .withQueryString("key" -> ustreamApiKey) .get().map { _.json.asOpt[Ustream.Result] ?? (_.streamsOnAir take max) } - twitch |+| ustream map StreamsOnAir.apply pipeTo self + twitch |+| chesswhiz map StreamsOnAir.apply pipeTo self case StreamsOnAir(streams) => onAir = streams } diff --git a/project/Build.scala b/project/Build.scala index 7d650c7ac2..99d7e1c27d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -114,7 +114,7 @@ object ApplicationBuild extends Build { play.api, RM, PRM, elastic4s) ) - lazy val tv = project("tv", Seq(common, db, hub, game, chess)).settings( + lazy val tv = project("tv", Seq(common, db, hub, game, user, chess)).settings( libraryDependencies ++= provided( play.api, RM, PRM) ) diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index bf6afa1c8d..1e7dd50669 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -1978,6 +1978,13 @@ div.lichess_overboard.joining .mini_board { #site_header a.stream:hover { text-decoration: underline; } +#site_header a.stream span { + color: #d59120; + font-weight: bold; +} +#site_header a.stream span:before { + vertical-align: -3px; +} #timeline { margin-top: 2em; border-top: 1px solid #e4e4e4;