resync lobby hooks on schedule

This commit is contained in:
Thibault Duplessis 2013-07-24 13:26:26 +02:00
parent 1f091e861e
commit 197b5d4a09
6 changed files with 25 additions and 9 deletions

View file

@ -51,6 +51,9 @@ final class Env(
scheduler.message(1 seconds) { scheduler.message(1 seconds) {
lobby -> lila.socket.actorApi.Broom lobby -> lila.socket.actorApi.Broom
} }
scheduler.message(10 seconds) {
socket -> actorApi.Resync
}
} }
} }

View file

@ -2,10 +2,9 @@ package lila.lobby
import scala.concurrent.duration._ import scala.concurrent.duration._
import actorApi._
import akka.actor._ import akka.actor._
import akka.pattern.{ ask, pipe } import akka.pattern.{ ask, pipe }
import actorApi._
import lila.db.api._ import lila.db.api._
import lila.hub.actorApi.GetUids import lila.hub.actorApi.GetUids
import lila.memo.ExpireSetMemo import lila.memo.ExpireSetMemo
@ -18,7 +17,7 @@ private[lobby] final class Lobby(
def receive = { def receive = {
case GetOpen sender ! HookRepo.allOpen case GetOpen sender ! HookRepo.allOpen
case msg @ AddHook(hook) { case msg @ AddHook(hook) {
HookRepo byUid hook.uid foreach remove HookRepo byUid hook.uid foreach remove
@ -47,6 +46,8 @@ private[lobby] final class Lobby(
HookRepo.cleanupOld foreach remove HookRepo.cleanupOld foreach remove
} }
} }
case Resync socket ! HookIds(HookRepo.list map (_.id))
} }
private def remove(hook: Hook) = { private def remove(hook: Hook) = {

View file

@ -2,13 +2,9 @@ package lila.lobby
import scala.concurrent.duration._ import scala.concurrent.duration._
import actorApi._
import akka.actor._ import akka.actor._
import akka.pattern.ask 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.game.actorApi._
import lila.hub.actorApi.lobby._ import lila.hub.actorApi.lobby._
import lila.hub.actorApi.router.{ Homepage, Player } import lila.hub.actorApi.router.{ Homepage, Player }
@ -16,6 +12,9 @@ import lila.hub.actorApi.timeline._
import lila.socket.actorApi.{ Connected _, _ } import lila.socket.actorApi.{ Connected _, _ }
import lila.socket.{ SocketActor, History, Historical } import lila.socket.{ SocketActor, History, Historical }
import makeTimeout.short import makeTimeout.short
import play.api.libs.iteratee._
import play.api.libs.json._
import play.api.templates.Html
private[lobby] final class Socket( private[lobby] final class Socket(
val history: History, val history: History,
@ -58,9 +57,11 @@ private[lobby] final class Socket(
} }
case ChangeFeatured(html) notifyFeatured(html) 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] router ? Player(fullId) mapTo manifest[String]
private def notifyFeatured(html: Html) { private def notifyFeatured(html: Html) {

View file

@ -26,5 +26,7 @@ case class CancelHook(uid: String)
case class BiteHook(hookId: String, uid: String, userId: Option[String]) case class BiteHook(hookId: String, uid: String, userId: Option[String])
case class JoinHook(uid: String, hook: Hook, game: Game) case class JoinHook(uid: String, hook: Hook, game: Game)
case class Join(uid: String, user: Option[User]) case class Join(uid: String, user: Option[User])
case object Resync
case class HookIds(ids: List[String])
case object GetOpen case object GetOpen

View file

@ -2081,6 +2081,7 @@ var storage = {
}, },
hook_add: addHook, hook_add: addHook,
hook_remove: removeHook, hook_remove: removeHook,
hook_list: syncHookIds,
featured: changeFeatured, featured: changeFeatured,
redirect: function(e) { redirect: function(e) {
$.lichessOpeningPreventClicks(); $.lichessOpeningPreventClicks();
@ -2124,6 +2125,13 @@ var storage = {
drawHooks(); drawHooks();
} }
function syncHookIds(ids) {
pool = _.filter(pool, function(h) {
return _.contains(ids, h.id);
});
drawHooks();
}
function addHook(hook, inBatch) { function addHook(hook, inBatch) {
if (!isRegistered && hook.mode == "Casual" && !hook.allowAnon) return; if (!isRegistered && hook.mode == "Casual" && !hook.allowAnon) return;
if (!isRegistered && hook.mode == "Rated") hook.action = 'register'; if (!isRegistered && hook.mode == "Rated") hook.action = 'register';

1
todo
View file

@ -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 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/ embedded games links http://2ls.ru/chessonline/
filter ranges http://en.lichess.org/forum/lichess-feedback/my-proposed-changes-with-filter-window#1 filter ranges http://en.lichess.org/forum/lichess-feedback/my-proposed-changes-with-filter-window#1
hooks resync (chrome does not remove them all)