From 197b5d4a093bda644ca6087da44a080fb0aecc9c Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 24 Jul 2013 13:26:26 +0200 Subject: [PATCH] resync lobby hooks on schedule --- modules/lobby/src/main/Env.scala | 3 +++ modules/lobby/src/main/Lobby.scala | 7 ++++--- modules/lobby/src/main/Socket.scala | 13 +++++++------ modules/lobby/src/main/actorApi.scala | 2 ++ public/javascripts/big.js | 8 ++++++++ todo | 1 + 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/modules/lobby/src/main/Env.scala b/modules/lobby/src/main/Env.scala index f2d1ec9735..95f7cdcb53 100644 --- a/modules/lobby/src/main/Env.scala +++ b/modules/lobby/src/main/Env.scala @@ -51,6 +51,9 @@ final class Env( scheduler.message(1 seconds) { lobby -> lila.socket.actorApi.Broom } + scheduler.message(10 seconds) { + socket -> actorApi.Resync + } } } diff --git a/modules/lobby/src/main/Lobby.scala b/modules/lobby/src/main/Lobby.scala index a5027ffb71..859ec4ef75 100644 --- a/modules/lobby/src/main/Lobby.scala +++ b/modules/lobby/src/main/Lobby.scala @@ -2,10 +2,9 @@ package lila.lobby import scala.concurrent.duration._ +import actorApi._ import akka.actor._ import akka.pattern.{ ask, pipe } - -import actorApi._ import lila.db.api._ import lila.hub.actorApi.GetUids import lila.memo.ExpireSetMemo @@ -18,7 +17,7 @@ private[lobby] final class Lobby( def receive = { - case GetOpen ⇒ sender ! HookRepo.allOpen + case GetOpen ⇒ sender ! HookRepo.allOpen case msg @ AddHook(hook) ⇒ { HookRepo byUid hook.uid foreach remove @@ -47,6 +46,8 @@ private[lobby] final class Lobby( HookRepo.cleanupOld foreach remove } } + + case Resync ⇒ socket ! HookIds(HookRepo.list map (_.id)) } private def remove(hook: Hook) = { diff --git a/modules/lobby/src/main/Socket.scala b/modules/lobby/src/main/Socket.scala index 509e595e07..7e289cb13d 100644 --- a/modules/lobby/src/main/Socket.scala +++ b/modules/lobby/src/main/Socket.scala @@ -2,13 +2,9 @@ package lila.lobby import scala.concurrent.duration._ +import actorApi._ import akka.actor._ import akka.pattern.ask -import play.api.libs.iteratee._ -import play.api.libs.json._ -import play.api.templates.Html - -import actorApi._ import lila.game.actorApi._ import lila.hub.actorApi.lobby._ import lila.hub.actorApi.router.{ Homepage, Player } @@ -16,6 +12,9 @@ import lila.hub.actorApi.timeline._ import lila.socket.actorApi.{ Connected ⇒ _, _ } import lila.socket.{ SocketActor, History, Historical } import makeTimeout.short +import play.api.libs.iteratee._ +import play.api.libs.json._ +import play.api.templates.Html private[lobby] final class Socket( val history: History, @@ -58,9 +57,11 @@ private[lobby] final class Socket( } case ChangeFeatured(html) ⇒ notifyFeatured(html) + + case HookIds(ids) ⇒ notifyVersion("hook_list", ids) } - private def playerUrl(fullId: String) = + private def playerUrl(fullId: String) = router ? Player(fullId) mapTo manifest[String] private def notifyFeatured(html: Html) { diff --git a/modules/lobby/src/main/actorApi.scala b/modules/lobby/src/main/actorApi.scala index 34b9793829..e046c925d8 100644 --- a/modules/lobby/src/main/actorApi.scala +++ b/modules/lobby/src/main/actorApi.scala @@ -26,5 +26,7 @@ case class CancelHook(uid: String) case class BiteHook(hookId: String, uid: String, userId: Option[String]) case class JoinHook(uid: String, hook: Hook, game: Game) case class Join(uid: String, user: Option[User]) +case object Resync +case class HookIds(ids: List[String]) case object GetOpen diff --git a/public/javascripts/big.js b/public/javascripts/big.js index a979264578..5da614d969 100644 --- a/public/javascripts/big.js +++ b/public/javascripts/big.js @@ -2081,6 +2081,7 @@ var storage = { }, hook_add: addHook, hook_remove: removeHook, + hook_list: syncHookIds, featured: changeFeatured, redirect: function(e) { $.lichessOpeningPreventClicks(); @@ -2124,6 +2125,13 @@ var storage = { drawHooks(); } + function syncHookIds(ids) { + pool = _.filter(pool, function(h) { + return _.contains(ids, h.id); + }); + drawHooks(); + } + function addHook(hook, inBatch) { if (!isRegistered && hook.mode == "Casual" && !hook.allowAnon) return; if (!isRegistered && hook.mode == "Rated") hook.action = 'register'; diff --git a/todo b/todo index 9d17a286bb..c607ddb3a9 100644 --- a/todo +++ b/todo @@ -57,3 +57,4 @@ customize sound notifications http://imgur.com/70WVyb5 opera issue http://en.lichess.org/forum/lichess-feedback/new-game-wont-show-on-games-list-opera#1 embedded games links http://2ls.ru/chessonline/ filter ranges http://en.lichess.org/forum/lichess-feedback/my-proposed-changes-with-filter-window#1 +hooks resync (chrome does not remove them all)