Skip to content

Commit

Permalink
remove tournament lobby message on cancelation
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 30, 2012
1 parent 51fefd2 commit f0e0f0e
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 49 deletions.
3 changes: 1 addition & 2 deletions app/core/CoreEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ final class CoreEnv private (application: Application, val settings: Settings) {
timelinePush = timeline.push.apply,
flood = security.flood,
siteSocket = site.socket,
lobbyNotify = lobby.socket.reloadTournaments,
lobbyMessage = lobby.socket.sysTalk,
lobbySocket = lobby.socket,
roundMeddler = round.meddler,
incToints = user.userRepo.incToints,
mongodb = mongodb.apply _)
Expand Down
10 changes: 7 additions & 3 deletions app/lobby/Hub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ final class Hub(
))
}

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

case ReloadTournaments(html) => notifyTournaments(html)
case UnTalk(regex) messenger.remove(regex).unsafePerformIO ~ { _
notifyVersion("untalk", Seq("regex" -> JsString(regex.toString)))
}

case ReloadTournaments(html) notifyTournaments(html)

case AddEntry(entry) notifyVersion("entry", JsString(entry.render))
case AddEntry(entry) notifyVersion("entry", JsString(entry.render))

case AddHook(hook) notifyVersion("hook_add", Seq(
"id" -> JsString(hook.id),
Expand Down
11 changes: 5 additions & 6 deletions app/lobby/MessageRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ final class MessageRepo(collection: MongoCollection, max: Int)
"t" -> obj.text)

def censorUsername(username: String): IO[Unit] = io {
collection.update(
DBObject("u" -> username),
$set("t" -> ""),
upsert = false,
multi = true
)
collection.update(DBObject("u" -> username), $set("t" -> ""), upsert = false, multi = true)
}

def removeRegex(regex: util.matching.Regex): IO[Unit] = io {
collection.update(DBObject("t" -> regex), $set("t" -> ""), upsert = false, multi = true)
}
}
2 changes: 2 additions & 0 deletions app/lobby/Messenger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ final class Messenger(
}

def mute(username: String): IO[Unit] = messageRepo censorUsername username

val remove = messageRepo.removeRegex _
}
38 changes: 14 additions & 24 deletions app/lobby/Socket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ final class Socket(hub: ActorRef, flood: Flood) {

implicit val timeout = Timeout(1 second)

def addEntry(entry: Entry): IO[Unit] = io { hub ! AddEntry(entry) }

def removeHook(hook: Hook): IO[Unit] = io { hub ! RemoveHook(hook) }

def addHook(hook: Hook): IO[Unit] = io { hub ! AddHook(hook) }

def biteHook(hook: Hook, game: DbGame): IO[Unit] = io { hub ! BiteHook(hook, game) }

def reloadTournaments(html: String): IO[Unit] = io { hub ! ReloadTournaments(html) }

def sysTalk(text: String): IO[Unit] = io { hub ! SysTalk(text) }

def unTalk(regex: util.matching.Regex): IO[Unit] = io { hub ! UnTalk(regex) }

def join(
uidOption: Option[String],
username: Option[String],
Expand Down Expand Up @@ -53,28 +67,4 @@ final class Socket(hub: ActorRef, flood: Flood) {
}: SocketPromise
promise | Util.connectionFail
}

def addEntry(entry: Entry): IO[Unit] = io {
hub ! AddEntry(entry)
}

def removeHook(hook: Hook): IO[Unit] = io {
hub ! RemoveHook(hook)
}

def addHook(hook: Hook): IO[Unit] = io {
hub ! AddHook(hook)
}

def biteHook(hook: Hook, game: DbGame): IO[Unit] = io {
hub ! BiteHook(hook, game)
}

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 @@ -28,6 +28,7 @@ case class Join(
hookOwnerId: Option[String])
case class Talk(u: String, txt: String)
case class SysTalk(txt: String)
case class UnTalk(r: util.matching.Regex)
case class Connected(
enumerator: JsEnumerator,
channel: JsChannel)
2 changes: 1 addition & 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 = 14
val assetVersion = 15

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

Expand Down
19 changes: 12 additions & 7 deletions app/tournament/TournamentApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import play.api.libs.json._
import controllers.routes
import game.DbGame
import user.User
import lobby.{ Socket LobbySocket }

private[tournament] final class TournamentApi(
repo: TournamentRepo,
joiner: GameJoiner,
socket: Socket,
siteSocket: site.Socket,
lobbyNotify: String IO[Unit],
lobbyMessage: String IO[Unit],
lobbySocket: LobbySocket,
roundMeddler: round.Meddler,
incToints: String Int IO[Unit]) {

Expand Down Expand Up @@ -57,6 +57,7 @@ private[tournament] final class TournamentApi(
_ repo removeIO created
_ reloadSiteSocket
_ lobbyReload
_ removeLobbyMessage(created)
} yield ()) doIf created.isEmpty

def finish(started: Started): IO[Tournament] = started.readyToFinish.fold({
Expand Down Expand Up @@ -120,18 +121,22 @@ private[tournament] final class TournamentApi(
.flatMap(_.userId)
.filter(_ List(chess.Status.Timeout, chess.Status.Outoftime) contains game.status)

private def lobbyReload = for {
tours repo.created
_ lobbyNotify(views.html.tournament.createdTable(tours).toString)
} yield ()
private def lobbyReload = repo.created flatMap { tours
lobbySocket reloadTournaments views.html.tournament.createdTable(tours).toString
}

private val reloadMessage = JsObject(Seq("t" -> JsString("reload"), "d" -> JsNull))
private def sendToSiteSocket(message: JsObject) = io {
siteSocket.sendToFlag("tournament", message)
}
private val reloadSiteSocket = sendToSiteSocket(reloadMessage)

private def sendLobbyMessage(tour: Created) = lobbyMessage {
private def sendLobbyMessage(tour: Created) = lobbySocket sysTalk {
"""<a href="%s">%s tournament created</a>""".format(routes.Tournament.show(tour.id), tour.name)
}

private def removeLobbyMessage(tour: Created) = lobbySocket unTalk {
("%s tournament created" format tour.name).r
}

}
9 changes: 4 additions & 5 deletions app/tournament/TournamentEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import game.{ GameRepo, DbGame }
import user.User
import core.Settings
import security.Flood
import lobby.{ Socket LobbySocket }
import socket.History
import memo.MonoMemo

Expand All @@ -23,8 +24,7 @@ final class TournamentEnv(
timelinePush: DbGame IO[Unit],
flood: Flood,
siteSocket: site.Socket,
lobbyNotify: String IO[Unit],
lobbyMessage: String IO[Unit],
lobbySocket: LobbySocket,
roundMeddler: round.Meddler,
incToints: String Int IO[Unit],
mongodb: String MongoCollection) {
Expand All @@ -42,8 +42,7 @@ final class TournamentEnv(
joiner = joiner,
socket = socket,
siteSocket = siteSocket,
lobbyNotify = lobbyNotify,
lobbyMessage = lobbyMessage,
lobbySocket = lobbySocket,
roundMeddler = roundMeddler,
incToints = incToints)

Expand Down Expand Up @@ -77,7 +76,7 @@ final class TournamentEnv(
reminder = reminder,
hubMaster = hubMaster
)), name = ActorTournamentOrganizer)

lazy val reminder = Akka.system.actorOf(Props(new Reminder(List(
ActorLobbyHub, ActorSiteHub, ActorRoundHubMaster, ActorTournamentHubMaster
))), name = ActorTournamentReminder)
Expand Down
9 changes: 8 additions & 1 deletion public/javascripts/big.js
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ $(function() {
});

////////////////
// opening.js //
// lobby.js //
////////////////

$(function() {
Expand Down Expand Up @@ -1537,6 +1537,12 @@ $(function() {
html += '</span>' + urlToLink(txt) + '</li>';
return html;
}
function removeFromChat(regex) {
var r = new RegExp(regex);
$chat.find('.lichess_messages li').filter(function() {
return r.test($(this).html());
}).remove();
}

$bot.on("click", "tr", function() { location.href = $(this).find('a.watch').attr("href"); });
$bot.find('.undertable_inner').scrollable();
Expand Down Expand Up @@ -1569,6 +1575,7 @@ $(function() {
},
events: {
talk: function(e) { if (chatExists && e.txt) addToChat(buildChatMessage(e.txt, e.u)); },
untalk: function(e) { if (chatExists && e.regex) removeFromChat(e.regex); },
entry: function(e) { renderTimeline([e]); },
hook_add: addHook,
hook_remove: removeHook,
Expand Down
3 changes: 3 additions & 0 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ not possible to copy the link URL invite when using a iOS device. Can this be ea
search bug http:https://en.lichess.org/games/search?players.a=&players.b=&players.winner=&eloMin=&eloMax=&hasAi=&aiLevelMin=&aiLevelMax=&variant=&mode=1&opening=&turnsMin=&turnsMax=&durationMin=&durationMax=&status=35&dateMin=&dateMax=&sort.field=tu&sort.order=asc
takeback substract time for person granting
add fullscreen mode for spectators and load new games in a loop (based on certain filter options) - thus creating a chess tv channel
remove tournament lobby message on cancel
make chess captcha more usable
shutdown ai on absence of messages

0 comments on commit f0e0f0e

Please sign in to comment.