From 8b3abe650f50c031133af979dddf72e94dfeafff Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Tue, 24 Sep 2013 15:32:55 +0200 Subject: [PATCH] hide blocking and blockers hooks --- app/Env.scala | 1 + app/mashup/Preload.scala | 8 ++++++-- modules/relation/src/main/RelationApi.scala | 2 ++ modules/user/src/main/User.scala | 4 +++- modules/user/src/main/UserRepo.scala | 13 +++++++------ project/Dependencies.scala | 2 +- public/javascripts/big.js | 1 + 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/Env.scala b/app/Env.scala index 8ab67fa1b5..4a2ead08fa 100644 --- a/app/Env.scala +++ b/app/Env.scala @@ -21,6 +21,7 @@ final class Env( lobby = Env.lobby.lobby, history = Env.lobby.history, featured = Env.game.featured, + relations = Env.relation.api, recentGames = () ⇒ Env.timeline.getter.recentGames, timelineEntries = Env.timeline.getter.userEntries _) diff --git a/app/mashup/Preload.scala b/app/mashup/Preload.scala index 2a097fec9b..0672fd3944 100644 --- a/app/mashup/Preload.scala +++ b/app/mashup/Preload.scala @@ -16,12 +16,14 @@ import lila.socket.History import lila.timeline.{ Entry, GameEntry } import lila.tournament.Created import lila.user.{ User, Context } +import lila.relation.RelationApi import makeTimeout.large final class Preload( lobby: ActorRef, history: History, featured: Featured, + relations: RelationApi, recentGames: () ⇒ Fu[List[GameEntry]], timelineEntries: String ⇒ Fu[List[Entry]]) { @@ -37,13 +39,15 @@ final class Preload( posts zip tours zip featured.one zip + (ctx.userId ?? relations.blocks) zip (ctx.userId ?? timelineEntries) zip filter map { - case ((((((hooks, gameEntries), posts), tours), feat), entries), filter) ⇒ + case (((((((hooks, gameEntries), posts), tours), feat), blocks), entries), filter) ⇒ (Right((Json.obj( "version" -> history.version, "pool" -> JsArray(hooks map (_.render)), - "filter" -> filter.render + "filter" -> filter.render, + "blocks" -> blocks ), entries, gameEntries, posts, tours, feat))) } } diff --git a/modules/relation/src/main/RelationApi.scala b/modules/relation/src/main/RelationApi.scala index efc07386ae..d06075efc3 100644 --- a/modules/relation/src/main/RelationApi.scala +++ b/modules/relation/src/main/RelationApi.scala @@ -22,6 +22,8 @@ final class RelationApi( def blockers(userId: ID) = cached blockers userId def blocking(userId: ID) = cached blocking userId + def blocks(userId: ID) = blockers(userId) ⊹ blocking(userId) + def nbFollowers(userId: ID) = followers(userId) map (_.size) def nbFollowing(userId: ID) = following(userId) map (_.size) def nbBlockers(userId: ID) = blockers(userId) map (_.size) diff --git a/modules/user/src/main/User.scala b/modules/user/src/main/User.scala index b6cd7b8b0c..b2eab99544 100644 --- a/modules/user/src/main/User.scala +++ b/modules/user/src/main/User.scala @@ -49,6 +49,8 @@ case class User( object User { + type ID = String + val STARTING_ELO = 1200 val anonymous = "Anonymous" @@ -80,5 +82,5 @@ object User { "toints" -> 0, "roles" -> Json.arr(), "seenAt" -> none[DateTime], - "lang" -> none[String] ) + "lang" -> none[String]) } diff --git a/modules/user/src/main/UserRepo.scala b/modules/user/src/main/UserRepo.scala index da6167263a..6569e8f531 100644 --- a/modules/user/src/main/UserRepo.scala +++ b/modules/user/src/main/UserRepo.scala @@ -1,20 +1,21 @@ package lila.user import com.roundeights.hasher.Implicits._ -import lila.common.PimpedJson._ -import lila.db.api._ -import lila.db.Implicits._ import org.joda.time.DateTime import ornicar.scalalib.Random import play.api.libs.json._ import play.modules.reactivemongo.json.BSONFormats.toJSON import play.modules.reactivemongo.json.ImplicitBSONHandlers.JsObjectWriter import reactivemongo.api._ + +import lila.common.PimpedJson._ +import lila.db.api._ +import lila.db.Implicits._ import tube.userTube object UserRepo { - type ID = String + import User.ID val normalize = User normalize _ @@ -26,10 +27,10 @@ object UserRepo { def topBlitz = topSpeed("blitz") _ def topSlow = topSpeed("slow") _ - def topSpeed(speed: String)(nb: Int): Fu[List[User]] = + def topSpeed(speed: String)(nb: Int): Fu[List[User]] = $find(goodLadQuery sort ($sort desc "speedElos." + speed + ".elo"), nb) - def topNbGame(nb: Int): Fu[List[User]] = + def topNbGame(nb: Int): Fu[List[User]] = $find(goodLadQuery sort ($sort desc "count.game"), nb) def byId(id: ID): Fu[Option[User]] = $find byId id diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c586e1b027..6e831d3ffc 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -32,7 +32,7 @@ object Dependencies { } val scalaz = "org.scalaz" %% "scalaz-core" % "7.0.3" - val scalalib = "com.github.ornicar" %% "scalalib" % "4.18" + val scalalib = "com.github.ornicar" %% "scalalib" % "4.19" val config = "com.typesafe" % "config" % "1.0.2" val apache = "org.apache.commons" % "commons-lang3" % "3.1" val scalaTime = "org.scala-tools.time" % "time_2.9.1" % "0.5" diff --git a/public/javascripts/big.js b/public/javascripts/big.js index e0fdb95b63..c374ff86ab 100644 --- a/public/javascripts/big.js +++ b/public/javascripts/big.js @@ -2204,6 +2204,7 @@ var storage = { function addHook(hook, inBatch) { if (!isRegistered && hook.mode == "Casual" && !hook.allowAnon) return; + if (_.contains(lichess_preload.blocks, hook.username.toLowerCase())) return; if (!isRegistered && hook.mode == "Rated") hook.action = 'register'; else hook.action = hook.uid == lichess_sri ? "cancel" : "join"; if (hook.action == 'join' && hook.emin && myElo && (myElo < parseInt(hook.emin) || myElo > parseInt(hook.emax))) return;