better user TV WIP

userTv
Thibault Duplessis 2016-01-31 12:57:17 +07:00
parent bca6fbfc58
commit e357e2722e
5 changed files with 13 additions and 10 deletions

View File

@ -81,7 +81,9 @@ object Round extends LilaController with TheftPrevention {
Env.api.roundApi.player(pov, apiVersion) map { Ok(_) }
}
}
) map NoCache
) map NoCache addEffect {
_ => ctx.userId foreach env.userTvChange
}
def player(fullId: String) = Open { implicit ctx =>
OptionFuResult(GameRepo pov fullId) { pov =>

View File

@ -72,11 +72,6 @@ final class Env(
def onStart(gameId: String) = GameRepo game gameId foreach {
_ foreach { game =>
system.lilaBus.publish(actorApi.StartGame(game), 'startGame)
game.userIds foreach { userId =>
system.lilaBus.publish(
actorApi.UserStartGame(userId, game),
Symbol(s"userStartGame:$userId"))
}
}
}

View File

@ -7,7 +7,7 @@ import play.api.libs.json.JsObject
import play.twirl.api.Html
case class StartGame(game: Game)
case class UserStartGame(userId: String, game: Game)
case class UserTvChange(userId: String)
case class FinishGame(game: Game, white: Option[User], black: Option[User]) {
def isVsSelf = white.isDefined && white == black

View File

@ -199,6 +199,12 @@ final class Env(
else if (pov.game.playable)
roundMap ! Tell(pov.game.id, actorApi.round.Resign(pov.playerId))
}
def userTvChange(userId: String) {
system.lilaBus.publish(
lila.game.actorApi.UserTvChange(userId),
Symbol(s"userTvChange:$userId"))
}
}
object Env {

View File

@ -10,7 +10,7 @@ import play.api.libs.json._
import actorApi._
import lila.common.LightUser
import lila.game.actorApi.{ StartGame, UserStartGame }
import lila.game.actorApi.{ StartGame, UserTvChange }
import lila.game.Event
import lila.hub.actorApi.Deploy
import lila.hub.actorApi.game.ChangeFeatured
@ -84,7 +84,7 @@ private[round] final class Socket(
private def refreshSubscriptions {
lilaBus.unsubscribe(self)
watchers.flatMap(_.userTv).toList.distinct foreach { userId =>
lilaBus.subscribe(self, Symbol(s"userStartGame:$userId"))
lilaBus.subscribe(self, Symbol(s"userTvChange:$userId"))
}
}
@ -174,7 +174,7 @@ private[round] final class Socket(
case TvSelect(msg) => watchers.foreach(_ push msg)
case UserStartGame(userId, game) => watchers filter (_ onUserTv userId) foreach {
case UserTvChange(userId) => watchers filter (_ onUserTv userId) foreach {
_ push makeMessage("resync")
}