Skip to content

Commit

Permalink
notify tournament creation in the lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 30, 2012
1 parent f4321b6 commit 51fefd2
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/core/CoreEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ final class CoreEnv private (application: Application, val settings: Settings) {
flood = security.flood,
siteSocket = site.socket,
lobbyNotify = lobby.socket.reloadTournaments,
lobbyMessage = lobby.socket.sysTalk,
roundMeddler = round.meddler,
incToints = user.userRepo.incToints,
mongodb = mongodb.apply _)
Expand Down
4 changes: 4 additions & 0 deletions app/lobby/Hub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ final class Hub(
))
}

case SysTalk(txt) messenger.system(txt).unsafePerformIO |> { message
notifyVersion("talk", Seq("txt" -> JsString(message.text)))
}

case ReloadTournaments(html) => notifyTournaments(html)

case AddEntry(entry) notifyVersion("entry", JsString(entry.render))
Expand Down
4 changes: 1 addition & 3 deletions app/lobby/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ case class Message(
username: String,
text: String) {

def render = Map(
"txt" -> text,
"u" -> username)
def render = Map("txt" -> text, "u" -> username)

def createdAt = new DateTime(id.getTime)

Expand Down
4 changes: 4 additions & 0 deletions app/lobby/Messenger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ final class Messenger(
_ message.fold(_ io(), messageRepo.add)
} yield message

def system(text: String): IO[Message] = Message(username = "", text = text) |> { message =>
messageRepo add message inject message
}

def mute(username: String): IO[Unit] = messageRepo censorUsername username
}
4 changes: 4 additions & 0 deletions app/lobby/Socket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ final class Socket(hub: ActorRef, flood: Flood) {
def reloadTournaments(html: String): IO[Unit] = io {
hub ! ReloadTournaments(html)
}

def sysTalk(text: String): IO[Unit] = io {
hub ! SysTalk(text)
}
}
1 change: 1 addition & 0 deletions app/lobby/actorApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ case class Join(
version: Int,
hookOwnerId: Option[String])
case class Talk(u: String, txt: String)
case class SysTalk(txt: String)
case class Connected(
enumerator: JsEnumerator,
channel: JsChannel)
8 changes: 7 additions & 1 deletion app/templating/AssetHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import play.api.templates.Html

trait AssetHelper {

val assetVersion = 13
val assetVersion = 14

def cssTag(name: String) = css("stylesheets/" + name)

Expand All @@ -29,4 +29,10 @@ trait AssetHelper {
def jsAt(path: String) = Html {
"""<script src="%s?v=%d"></script>""".format(path, assetVersion)
}

def embedJs(js: String): Html = Html("""<script type="text/javascript">
/* <![CDATA[ */
%s
/* ]]> */
</script>""" format js)
}
7 changes: 7 additions & 0 deletions app/tournament/TournamentApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scalaz.effects._
import scalaz.{ NonEmptyList, Success, Failure }
import play.api.libs.json._

import controllers.routes
import game.DbGame
import user.User

Expand All @@ -16,6 +17,7 @@ private[tournament] final class TournamentApi(
socket: Socket,
siteSocket: site.Socket,
lobbyNotify: String IO[Unit],
lobbyMessage: String IO[Unit],
roundMeddler: round.Meddler,
incToints: String Int IO[Unit]) {

Expand All @@ -39,6 +41,7 @@ private[tournament] final class TournamentApi(
_ (withdrawIds map socket.reload).sequence
_ reloadSiteSocket
_ lobbyReload
_ sendLobbyMessage(created)
} yield created

def start(created: Created): Option[IO[Unit]] = created.start map { started
Expand Down Expand Up @@ -127,4 +130,8 @@ private[tournament] final class TournamentApi(
siteSocket.sendToFlag("tournament", message)
}
private val reloadSiteSocket = sendToSiteSocket(reloadMessage)

private def sendLobbyMessage(tour: Created) = lobbyMessage {
"""<a href="%s">%s tournament created</a>""".format(routes.Tournament.show(tour.id), tour.name)
}
}
2 changes: 2 additions & 0 deletions app/tournament/TournamentEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class TournamentEnv(
flood: Flood,
siteSocket: site.Socket,
lobbyNotify: String IO[Unit],
lobbyMessage: String IO[Unit],
roundMeddler: round.Meddler,
incToints: String Int IO[Unit],
mongodb: String MongoCollection) {
Expand All @@ -42,6 +43,7 @@ final class TournamentEnv(
socket = socket,
siteSocket = siteSocket,
lobbyNotify = lobbyNotify,
lobbyMessage = lobbyMessage,
roundMeddler = roundMeddler,
incToints = incToints)

Expand Down
2 changes: 1 addition & 1 deletion app/views/lobby/home.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@
</div>
</div>
</div>
<script>var lichess_preload = @Html(preload);</script>
@embedJs("var lichess_preload = " + preload)
}
2 changes: 1 addition & 1 deletion app/views/round/player.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@round.cemetery(!pov, "bottom")
</div>
</div>
<script type="text/javascript">var _ld_ = @Html(roundPlayerJsData(pov, version))</script>
@embedJs("var _ld_ = " + roundPlayerJsData(pov, version))
@analyse.link(pov, analysed)
@if(!tour.fold(_.isRunning, false)) {
@views.html.game.more(pov, bookmarkers) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/round/watcher.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@round.cemetery(!pov, "bottom")
</div>
</div>
<script type="text/javascript">var _ld_ = @Html(roundWatcherJsData(pov, version))</script>
@embedJs("var _ld_ = " + roundWatcherJsData(pov, version))
@analyse.link(pov, analysed)
@views.html.game.more(pov, bookmarkers) {
<nav>
Expand Down
2 changes: 1 addition & 1 deletion app/views/setup/await.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
</div>
</div>
</div>
<script type="text/javascript">var _ld_ = @Html(roundPlayerJsData(pov, version))</script>
@embedJs("var _ld_ = " + roundPlayerJsData(pov, version))
}
2 changes: 1 addition & 1 deletion app/views/setup/join.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
</div>
</div>
</div>
<script type="text/javascript">var _ld_ = @Html(roundPlayerJsData(pov, version))</script>
@embedJs("var _ld_ = " + roundPlayerJsData(pov, version))
}
4 changes: 1 addition & 3 deletions app/views/tournament/show/layout.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,5 @@
data-socket-url="@routes.Tournament.websocket(tour.id)">
@tournament.show.inner(side)(body)
</div>
<script type="text/javascript">
var _ld_ = @Html(tournamentJsData(tour, version, ctx.me))
</script>
@embedJs("var _ld_ = " + tournamentJsData(tour, version, ctx.me))
}
10 changes: 6 additions & 4 deletions public/javascripts/big.js
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,11 @@ $(function() {
}
function buildChatMessage(txt, username) {
var html = '<li><span>';
html += '<a class="user_link" href="/@/'+username+'">'+username.substr(0, 12) + '</a>';
if (typeof username != "undefined" && username != "") {
html += '<a class="user_link" href="/@/'+username+'">'+username.substr(0, 12) + '</a>';
} else {
html += '-';
}
html += '</span>' + urlToLink(txt) + '</li>';
return html;
}
Expand Down Expand Up @@ -1575,9 +1579,7 @@ $(function() {
},
tournaments: reloadTournaments
},
options: {
name: "lobby"
}
options: { name: "lobby" }
}));
$('body').trigger('lichess.content_loaded');

Expand Down

0 comments on commit 51fefd2

Please sign in to comment.