From e2ed3471620c8c97b46efc3e0bb3d07aa6545864 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 12 Apr 2024 21:48:27 +0200 Subject: [PATCH] remove more deps --- app/controllers/Challenge.scala | 2 +- app/controllers/Insight.scala | 11 ++++++----- app/controllers/Puzzle.scala | 4 ++-- app/views/account/kid.scala | 2 +- app/views/account/pref.scala | 2 +- app/views/account/profile.scala | 2 +- app/views/account/security.scala | 2 +- app/views/account/username.scala | 2 +- app/views/analyse/replay.scala | 2 +- app/views/base/layout.scala | 2 +- app/views/clas/studentDashboard.scala | 2 +- app/views/game/bits.scala | 2 +- app/views/game/side.scala | 4 ++-- app/views/game/widgets.scala | 2 +- app/views/mod/impersonate.scala | 2 +- app/views/mod/table.scala | 2 +- app/views/oAuth/token/create.scala | 2 +- app/views/plan/indexPayPal.scala | 2 +- app/views/plan/indexStripe.scala | 2 +- app/views/round/bits.scala | 2 +- app/views/round/watcher.scala | 2 +- app/views/tutor/bits.scala | 2 +- app/views/tutor/opening.scala | 2 +- app/views/tutor/openings.scala | 2 +- app/views/tutor/phases.scala | 2 +- app/views/tutor/skills.scala | 2 +- app/views/tutor/time.scala | 2 +- app/views/user/download.scala | 2 +- build.sbt | 8 ++++---- modules/challenge/src/main/ChallengeJoiner.scala | 2 +- modules/challenge/src/main/ChallengeMaker.scala | 4 ++-- modules/challenge/src/main/ChallengeRepo.scala | 2 +- modules/core/src/main/user.scala | 7 ++++++- modules/gameSearch/src/main/Env.scala | 2 +- modules/gameSearch/src/main/GameSearchApi.scala | 4 ++-- modules/gameSearch/src/main/UserGameSearch.scala | 2 +- modules/mod/src/main/ModNotifier.scala | 2 +- modules/mod/src/main/RatingRefund.scala | 2 +- modules/perfStat/src/main/PerfStat.scala | 2 +- modules/plan/src/main/PlanApi.scala | 2 +- modules/pool/src/main/Env.scala | 3 +-- modules/pool/src/main/GameStarter.scala | 8 +++----- modules/setup/src/main/Env.scala | 2 +- modules/setup/src/main/Processor.scala | 7 +++---- modules/tournament/src/main/TournamentRepo.scala | 2 +- modules/tv/src/main/Env.scala | 2 +- modules/tv/src/main/TvSyncActor.scala | 2 +- modules/user/src/main/UserApi.scala | 11 ++++++----- 48 files changed, 74 insertions(+), 71 deletions(-) diff --git a/app/controllers/Challenge.scala b/app/controllers/Challenge.scala index a37c6de30e3b9..2763ac4efc12f 100644 --- a/app/controllers/Challenge.scala +++ b/app/controllers/Challenge.scala @@ -72,7 +72,7 @@ final class Challenge( else Ok.pageAsync: c.challengerUserId - .so(env.user.api.withPerf(_, c.perfType)) + .so(env.user.api.byIdWithPerf(_, c.perfType)) .map: html.challenge.theirs(c, json, _, color) , diff --git a/app/controllers/Insight.scala b/app/controllers/Insight.scala index 1c4d874d3d710..8d3da4b331b0b 100644 --- a/app/controllers/Insight.scala +++ b/app/controllers/Insight.scala @@ -7,7 +7,6 @@ import views.* import lila.app.{ *, given } import lila.insight.{ InsightDimension, InsightMetric } -import lila.user.User import lila.core.i18n.Translate final class Insight(env: Env) extends LilaController(env): @@ -28,7 +27,9 @@ final class Insight(env: Env) extends LilaController(env): def path(username: UserStr, metric: String, dimension: String, filters: String) = Open: Accessible(username) { doPath(_, metric, dimension, ~lila.common.String.decodeUriPath(filters)) } - private def doPath(user: User, metric: String, dimension: String, filters: String)(using Context) = + private def doPath(user: lila.user.User, metric: String, dimension: String, filters: String)(using + Context + ) = import lila.insight.InsightApi.UserStatus.* env.insight.api.userStatus(user).flatMap { case NoGame => Ok.page(html.site.message.insightNoGames(user)) @@ -54,7 +55,7 @@ final class Insight(env: Env) extends LilaController(env): OpenOrScopedBody(parse.json)(): ctx ?=> AccessibleApi(username) { processQuestion(_, ctx.body) } - private def processQuestion(user: User, body: Request[JsValue])(using Translate) = + private def processQuestion(user: lila.user.User, body: Request[JsValue])(using Translate) = body.body .validate[lila.insight.JsonQuestion] .fold( @@ -67,7 +68,7 @@ final class Insight(env: Env) extends LilaController(env): .map { Ok(_) } ) - private def Accessible(username: UserStr)(f: User => Fu[Result])(using ctx: Context) = + private def Accessible(username: UserStr)(f: lila.user.User => Fu[Result])(using ctx: Context) = Found(meOrFetch(username)): u => env.insight.share .grant(u)(using ctx.me) @@ -75,7 +76,7 @@ final class Insight(env: Env) extends LilaController(env): if _ then f(u) else Forbidden.page(html.insight.forbidden(u)) - private def AccessibleApi(username: UserStr)(f: User => Fu[Result])(using Context) = + private def AccessibleApi(username: UserStr)(f: lila.user.User => Fu[Result])(using Context) = Found(meOrFetch(username)): u => env.insight.share .grant(u)(using ctx.me) diff --git a/app/controllers/Puzzle.scala b/app/controllers/Puzzle.scala index 28b8ee3d322a4..3505938a8af01 100644 --- a/app/controllers/Puzzle.scala +++ b/app/controllers/Puzzle.scala @@ -25,7 +25,7 @@ import lila.puzzle.{ } import lila.rating.PerfType -import lila.user.User + import lila.core.i18n.Translate import lila.core.user.WithPerf @@ -521,7 +521,7 @@ final class Puzzle(env: Env, apiC: => Api) extends LilaController(env): def help = Open: Ok.page(html.site.help.puzzle) - private def DashboardPage(username: Option[UserStr])(f: Context ?=> User => Fu[Result]) = + private def DashboardPage(username: Option[UserStr])(f: Context ?=> lila.user.User => Fu[Result]) = Auth { ctx ?=> me ?=> meOrFetch(username) .flatMapz: user => diff --git a/app/views/account/kid.scala b/app/views/account/kid.scala index 0771918f35446..47974cb913f00 100644 --- a/app/views/account/kid.scala +++ b/app/views/account/kid.scala @@ -8,7 +8,7 @@ import lila.app.ui.ScalatagsTemplate.{ *, given } object kid: - def apply(u: lila.user.User, form: play.api.data.Form[?], managed: Boolean)(using PageContext) = + def apply(u: User, form: play.api.data.Form[?], managed: Boolean)(using PageContext) = account.layout( title = s"${u.username} - ${trans.site.kidMode.txt()}", active = "kid" diff --git a/app/views/account/pref.scala b/app/views/account/pref.scala index c7d3f8211649b..7e1aadb02efd2 100644 --- a/app/views/account/pref.scala +++ b/app/views/account/pref.scala @@ -17,7 +17,7 @@ object pref: private def setting(name: Frag, body: Frag, settingId: String) = st.section(a(href := "#" + settingId)(h2(id := settingId)(name)), body) - def apply(u: lila.user.User, form: play.api.data.Form[?], categ: lila.pref.PrefCateg)(using PageContext) = + def apply(u: User, form: play.api.data.Form[?], categ: lila.pref.PrefCateg)(using PageContext) = account.layout( title = s"${bits.categName(categ)} - ${u.username} - ${preferences.txt()}", active = categ.slug diff --git a/app/views/account/profile.scala b/app/views/account/profile.scala index 791e6f8d33c11..9f5db906c2a08 100644 --- a/app/views/account/profile.scala +++ b/app/views/account/profile.scala @@ -14,7 +14,7 @@ object profile: trans.site.oneUrlPerLine() ) - def apply(u: lila.user.User, form: play.api.data.Form[?])(using ctx: PageContext) = + def apply(u: User, form: play.api.data.Form[?])(using ctx: PageContext) = account.layout( title = s"${u.username} - ${trans.site.editProfile.txt()}", active = "editProfile" diff --git a/app/views/account/security.scala b/app/views/account/security.scala index 08122797d658e..4079997fb53b4 100644 --- a/app/views/account/security.scala +++ b/app/views/account/security.scala @@ -10,7 +10,7 @@ import lila.app.ui.ScalatagsTemplate.{ *, given } object security: def apply( - u: lila.user.User, + u: User, sessions: List[lila.security.LocatedSession], curSessionId: String, clients: List[lila.oauth.AccessTokenApi.Client], diff --git a/app/views/account/username.scala b/app/views/account/username.scala index abf276f39c6b3..4e4d5b76a65ac 100644 --- a/app/views/account/username.scala +++ b/app/views/account/username.scala @@ -8,7 +8,7 @@ import lila.app.ui.ScalatagsTemplate.{ *, given } object username: - def apply(u: lila.user.User, form: play.api.data.Form[?])(using PageContext) = + def apply(u: User, form: play.api.data.Form[?])(using PageContext) = account.layout( title = s"${u.username} - ${trans.site.editProfile.txt()}", active = "username" diff --git a/app/views/analyse/replay.scala b/app/views/analyse/replay.scala index 92bf204e1fdd9..c82a051e022b9 100644 --- a/app/views/analyse/replay.scala +++ b/app/views/analyse/replay.scala @@ -28,7 +28,7 @@ object replay: analysisStarted: Boolean, simul: Option[lila.simul.Simul], cross: Option[lila.game.Crosstable.WithMatchup], - userTv: Option[lila.user.User], + userTv: Option[User], chatOption: Option[lila.chat.UserChat.Mine], bookmarked: Boolean )(using ctx: PageContext) = diff --git a/app/views/base/layout.scala b/app/views/base/layout.scala index d87f1fdb7c34e..12a7321e89440 100644 --- a/app/views/base/layout.scala +++ b/app/views/base/layout.scala @@ -117,7 +117,7 @@ object layout: .txt()} """ - private def dasher(me: lila.user.User) = + private def dasher(me: User) = div(cls := "dasher")( a(id := "user_tag", cls := "toggle link", href := routes.Auth.logoutGet)(me.username), div(id := "dasher_app", cls := "dropdown") diff --git a/app/views/clas/studentDashboard.scala b/app/views/clas/studentDashboard.scala index 9b3a89f5e4b19..9e69494e4e81a 100644 --- a/app/views/clas/studentDashboard.scala +++ b/app/views/clas/studentDashboard.scala @@ -95,7 +95,7 @@ object studentDashboard: } ) - private def challengeTd(user: lila.user.User)(using ctx: PageContext) = + private def challengeTd(user: User)(using ctx: PageContext) = if ctx.is(user) then td else val online = isOnline(user.id) diff --git a/app/views/game/bits.scala b/app/views/game/bits.scala index d1e452a88bdd7..c0ea313aa3a55 100644 --- a/app/views/game/bits.scala +++ b/app/views/game/bits.scala @@ -23,7 +23,7 @@ object bits: tour: Option[lila.tournament.TourAndTeamVs], cross: Option[lila.game.Crosstable.WithMatchup], simul: Option[lila.simul.Simul], - userTv: Option[lila.user.User] = None, + userTv: Option[User] = None, bookmarked: Boolean )(using ctx: Context) = div( diff --git a/app/views/game/side.scala b/app/views/game/side.scala index 78ad50e5e9092..8a64480b1f1a5 100644 --- a/app/views/game/side.scala +++ b/app/views/game/side.scala @@ -17,7 +17,7 @@ object side: initialFen: Option[chess.format.Fen.Full], tour: Option[lila.tournament.TourAndTeamVs], simul: Option[lila.simul.Simul], - userTv: Option[lila.user.User] = None, + userTv: Option[User] = None, bookmarked: Boolean )(using ctx: Context): Option[Frag] = ctx.noBlind.option( @@ -32,7 +32,7 @@ object side: initialFen: Option[chess.format.Fen.Full], tour: Option[lila.tournament.TourAndTeamVs], simul: Option[lila.simul.Simul], - userTv: Option[lila.user.User] = None, + userTv: Option[User] = None, bookmarked: Boolean )(using ctx: Context): Option[Frag] = ctx.noBlind.option { diff --git a/app/views/game/widgets.scala b/app/views/game/widgets.scala index 0612ee7c83086..2a94cc10da913 100644 --- a/app/views/game/widgets.scala +++ b/app/views/game/widgets.scala @@ -12,7 +12,7 @@ object widgets: def apply( games: Seq[Game], notes: Map[GameId, String] = Map(), - user: Option[lila.user.User] = None, + user: Option[User] = None, ownerLink: Boolean = false )(using Context): Frag = games.map { g => diff --git a/app/views/mod/impersonate.scala b/app/views/mod/impersonate.scala index 3034275c70a02..3960fb375d314 100644 --- a/app/views/mod/impersonate.scala +++ b/app/views/mod/impersonate.scala @@ -8,7 +8,7 @@ import lila.app.ui.ScalatagsTemplate.{ *, given } object impersonate: - def apply(user: lila.user.User)(using Translate) = + def apply(user: User)(using Translate) = div(id := "impersonate")( div(cls := "meat")( "You are impersonating ", diff --git a/app/views/mod/table.scala b/app/views/mod/table.scala index 070b95d814859..af71d0fc03e75 100644 --- a/app/views/mod/table.scala +++ b/app/views/mod/table.scala @@ -9,7 +9,7 @@ object table: private val dataSort = attr("data-sort") - def apply(users: List[lila.user.User])(using PageContext) = + def apply(users: List[User])(using PageContext) = val title = "All mods" diff --git a/app/views/oAuth/token/create.scala b/app/views/oAuth/token/create.scala index 3a3ae99812be9..bc111ee9b2d05 100644 --- a/app/views/oAuth/token/create.scala +++ b/app/views/oAuth/token/create.scala @@ -9,7 +9,7 @@ import lila.core.i18n.I18nKey.oauthScope as ot object create: - def apply(form: Form[lila.oauth.OAuthTokenForm.Data], me: lila.user.User)(using PageContext) = + def apply(form: Form[lila.oauth.OAuthTokenForm.Data], me: User)(using PageContext) = val title = ot.newAccessToken diff --git a/app/views/plan/indexPayPal.scala b/app/views/plan/indexPayPal.scala index 12a5308dbc0fc..a22c8bdc7a907 100644 --- a/app/views/plan/indexPayPal.scala +++ b/app/views/plan/indexPayPal.scala @@ -12,7 +12,7 @@ object indexPayPal: private val dataForm = attr("data-form") def apply( - me: lila.user.User, + me: User, patron: lila.plan.Patron, subscription: lila.plan.PayPalSubscription, gifts: List[lila.plan.Charge.Gift] diff --git a/app/views/plan/indexStripe.scala b/app/views/plan/indexStripe.scala index 2cad4b8beeb49..3f8f88bb1ee4f 100644 --- a/app/views/plan/indexStripe.scala +++ b/app/views/plan/indexStripe.scala @@ -13,7 +13,7 @@ object indexStripe: private val dataForm = attr("data-form") def apply( - me: lila.user.User, + me: User, patron: lila.plan.Patron, info: lila.plan.CustomerInfo.Monthly, stripePublicKey: String, diff --git a/app/views/round/bits.scala b/app/views/round/bits.scala index 0c604f6c599a5..66db4b1bba58c 100644 --- a/app/views/round/bits.scala +++ b/app/views/round/bits.scala @@ -137,7 +137,7 @@ object bits: data: play.api.libs.json.JsObject, tour: Option[lila.tournament.TourAndTeamVs], simul: Option[lila.simul.Simul], - userTv: Option[lila.user.User] = None, + userTv: Option[User] = None, bookmarked: Boolean )(using Context) = views.html.game.side( diff --git a/app/views/round/watcher.scala b/app/views/round/watcher.scala index ed7853b86bc84..6d980954feec8 100644 --- a/app/views/round/watcher.scala +++ b/app/views/round/watcher.scala @@ -15,7 +15,7 @@ object watcher: tour: Option[lila.tournament.TourAndTeamVs], simul: Option[lila.simul.Simul], cross: Option[lila.game.Crosstable.WithMatchup], - userTv: Option[lila.user.User] = None, + userTv: Option[User] = None, chatOption: Option[lila.chat.UserChat.Mine], bookmarked: Boolean )(using ctx: PageContext) = diff --git a/app/views/tutor/bits.scala b/app/views/tutor/bits.scala index eebde17ce745d..cced88b0f9eed 100644 --- a/app/views/tutor/bits.scala +++ b/app/views/tutor/bits.scala @@ -22,7 +22,7 @@ object bits: def percentNumber[A](v: A)(using number: TutorNumber[A]) = f"${number.double(v)}%1.1f" def percentFrag[A](v: A)(using TutorNumber[A]) = frag(strong(percentNumber(v)), "%") - private[tutor] def otherUser(user: lila.user.User)(using ctx: Context) = + private[tutor] def otherUser(user: User)(using ctx: Context) = ctx.isnt(user).option(userSpan(user, withOnline = false)) private[tutor] def layout( diff --git a/app/views/tutor/opening.scala b/app/views/tutor/opening.scala index 25985170c1504..eba97426c9b44 100644 --- a/app/views/tutor/opening.scala +++ b/app/views/tutor/opening.scala @@ -13,7 +13,7 @@ object opening: perfReport: TutorPerfReport, report: TutorOpeningFamily, as: chess.Color, - user: lila.user.User, + user: User, puzzle: Option[lila.puzzle.PuzzleOpening.FamilyWithCount] )(using PageContext) = bits.layout( diff --git a/app/views/tutor/openings.scala b/app/views/tutor/openings.scala index 53b4ab864460e..94f33b9153cda 100644 --- a/app/views/tutor/openings.scala +++ b/app/views/tutor/openings.scala @@ -8,7 +8,7 @@ import lila.tutor.TutorPerfReport object openings: - def apply(report: TutorPerfReport, user: lila.user.User)(using ctx: PageContext) = + def apply(report: TutorPerfReport, user: User)(using ctx: PageContext) = bits.layout(menu = perf.menu(user, report, "openings"))( cls := "tutor__openings box", boxTop( diff --git a/app/views/tutor/phases.scala b/app/views/tutor/phases.scala index ebb144f721245..464362652da1d 100644 --- a/app/views/tutor/phases.scala +++ b/app/views/tutor/phases.scala @@ -9,7 +9,7 @@ import lila.tutor.TutorPerfReport object phases: - def apply(report: TutorPerfReport, user: lila.user.User)(using PageContext) = + def apply(report: TutorPerfReport, user: User)(using PageContext) = bits.layout(menu = perf.menu(user, report, "phases"))( cls := "tutor__phases box", boxTop( diff --git a/app/views/tutor/skills.scala b/app/views/tutor/skills.scala index c5464f746a59a..d6c79c7156af5 100644 --- a/app/views/tutor/skills.scala +++ b/app/views/tutor/skills.scala @@ -9,7 +9,7 @@ import lila.tutor.TutorPerfReport object skills: - def apply(report: TutorPerfReport, user: lila.user.User)(using PageContext) = + def apply(report: TutorPerfReport, user: User)(using PageContext) = bits.layout(menu = perf.menu(user, report, "skills"))( cls := "tutor__skills box", boxTop( diff --git a/app/views/tutor/time.scala b/app/views/tutor/time.scala index fed1d4c378b0e..847a7485e5248 100644 --- a/app/views/tutor/time.scala +++ b/app/views/tutor/time.scala @@ -9,7 +9,7 @@ import lila.tutor.TutorPerfReport object time: - def apply(report: TutorPerfReport, user: lila.user.User)(using PageContext) = + def apply(report: TutorPerfReport, user: User)(using PageContext) = bits.layout(menu = perf.menu(user, report, "time"))( cls := "tutor__time box", boxTop( diff --git a/app/views/user/download.scala b/app/views/user/download.scala index 1640f1e95e9cd..9496d86fbb7c5 100644 --- a/app/views/user/download.scala +++ b/app/views/user/download.scala @@ -8,7 +8,7 @@ import lila.app.ui.ScalatagsTemplate.{ *, given } import lila.rating.PerfType object download: - def apply(user: lila.user.User)(using ctx: PageContext): Frag = + def apply(user: User)(using ctx: PageContext): Frag = views.html.base.layout( title = s"${user.username} • ${trans.site.exportGames.txt()}", moreCss = cssTag("search"), diff --git a/build.sbt b/build.sbt index 60bf48fe34866..d74fe770677b2 100644 --- a/build.sbt +++ b/build.sbt @@ -225,12 +225,12 @@ lazy val game = module("game", ) lazy val gameSearch = module("gameSearch", - Seq(game, user, search), + Seq(game, search), reactivemongo.bundle ) lazy val tv = module("tv", - Seq(game, user), + Seq(game), Seq(hasher) ++ reactivemongo.bundle ) @@ -250,7 +250,7 @@ lazy val round = module("round", ) lazy val pool = module("pool", - Seq(game, user), + Seq(game), reactivemongo.bundle ) @@ -265,7 +265,7 @@ lazy val lobby = module("lobby", ) lazy val setup = module("setup", - Seq(lobby, user), + Seq(lobby), reactivemongo.bundle ) diff --git a/modules/challenge/src/main/ChallengeJoiner.scala b/modules/challenge/src/main/ChallengeJoiner.scala index 98efda1428fa9..9d2d6a48dbe88 100644 --- a/modules/challenge/src/main/ChallengeJoiner.scala +++ b/modules/challenge/src/main/ChallengeJoiner.scala @@ -20,7 +20,7 @@ final private class ChallengeJoiner( if _ then fuccess(Left("The challenge has already been accepted")) else c.challengerUserId - .so(userApi.withPerf(_, c.perfType)) + .so(userApi.byIdWithPerf(_, c.perfType)) .flatMap: origUser => val game = ChallengeJoiner.createGame(c, origUser, destUser) gameRepo diff --git a/modules/challenge/src/main/ChallengeMaker.scala b/modules/challenge/src/main/ChallengeMaker.scala index fadca5d19de9a..f224c2af82ac1 100644 --- a/modules/challenge/src/main/ChallengeMaker.scala +++ b/modules/challenge/src/main/ChallengeMaker.scala @@ -32,13 +32,13 @@ final class ChallengeMaker( .opponentOf(dest) .so: challenger => for - orig <- challenger.userId.so(userApi.withPerf(_, game.perfType)) + orig <- challenger.userId.so(userApi.byIdWithPerf(_, game.perfType)) dest <- perfsRepo.withPerf(dest, game.perfType) yield Data(game, challenger, orig, dest).some private[challenge] def makeRematchOf(game: Game, challenger: User): Fu[Option[Challenge]] = Pov(game, challenger.id).so: pov => - pov.opponent.userId.so(userApi.withPerf(_, game.perfType)).flatMapz { dest => + pov.opponent.userId.so(userApi.byIdWithPerf(_, game.perfType)).flatMapz { dest => for challenger <- perfsRepo.withPerf(challenger, game.perfType) rematch <- makeRematch(pov, challenger.some, dest) diff --git a/modules/challenge/src/main/ChallengeRepo.scala b/modules/challenge/src/main/ChallengeRepo.scala index ae9701c212831..c050fd162e117 100644 --- a/modules/challenge/src/main/ChallengeRepo.scala +++ b/modules/challenge/src/main/ChallengeRepo.scala @@ -15,7 +15,7 @@ final private class ChallengeRepo(colls: ChallengeColls)(using def byId(id: Challenge.Id) = coll.find($id(id)).one[Challenge] - def byIdFor(id: Challenge.Id, dest: lila.user.User) = + def byIdFor(id: Challenge.Id, dest: User) = coll.find($id(id) ++ $doc("destUser.id" -> dest.id)).one[Challenge] def exists(id: Challenge.Id) = coll.countSel($id(id)).dmap(0 <) diff --git a/modules/core/src/main/user.scala b/modules/core/src/main/user.scala index 83a7e15e85128..f24e5e1600af6 100644 --- a/modules/core/src/main/user.scala +++ b/modules/core/src/main/user.scala @@ -204,14 +204,17 @@ object user: def isManaged(id: UserId): Fu[Boolean] def countEngines(userIds: List[UserId]): Fu[Int] def getTitle(id: UserId): Fu[Option[PlayerTitle]] - def listWithPerfs[U: UserIdOf](us: List[U]): Fu[List[UserWithPerfs]] + def withPerf(id: User, pk: PerfKey): Fu[WithPerf] def withPerfs(u: User): Fu[UserWithPerfs] def withPerfs[U: UserIdOf](id: U): Fu[Option[UserWithPerfs]] + def listWithPerfs[U: UserIdOf](us: List[U]): Fu[List[UserWithPerfs]] def perfsOf[U: UserIdOf](u: U): Fu[UserPerfs] + def perfOf(ids: Iterable[UserId], perfKey: PerfKey): Fu[Map[UserId, Perf]] def dubiousPuzzle(id: UserId, puzzle: Perf): Fu[Boolean] def setPerf(userId: UserId, pk: PerfKey, perf: Perf): Funit def userIdsWithRoles(roles: List[String]): Fu[Set[UserId]] def incColor(userId: UserId, value: Int): Unit + def firstGetsWhite(u1: UserId, u2: UserId): Fu[Boolean] def firstGetsWhite(u1O: Option[UserId], u2O: Option[UserId]): Fu[Boolean] def gamePlayersAny(userIds: ByColor[Option[UserId]], perf: PerfKey): Fu[GameUsers] def gamePlayersLoggedIn( @@ -220,6 +223,7 @@ object user: useCache: Boolean = true ): Fu[Option[ByColor[WithPerf]]] def glicko(userId: UserId, perf: PerfKey): Fu[Glicko] + def containsDisabled(userIds: Iterable[UserId]): Fu[Boolean] trait LightUserApiMinimal: val async: LightUser.Getter @@ -227,6 +231,7 @@ object user: trait LightUserApi extends LightUserApiMinimal: val syncFallback: LightUser.GetterSyncFallback def preloadMany(ids: Seq[UserId]): Funit + val isBotSync: LightUser.IsBotSync case class Emails(current: Option[EmailAddress], previous: Option[NormalizedEmailAddress]): def strList = current.map(_.value).toList ::: previous.map(_.value).toList diff --git a/modules/gameSearch/src/main/Env.scala b/modules/gameSearch/src/main/Env.scala index 08673b4cad2a1..4141d3ffd6df9 100644 --- a/modules/gameSearch/src/main/Env.scala +++ b/modules/gameSearch/src/main/Env.scala @@ -18,7 +18,7 @@ private class GameSearchConfig( final class Env( appConfig: Configuration, gameRepo: lila.game.GameRepo, - userRepo: lila.user.UserRepo, + userApi: lila.core.user.UserApi, makeClient: Index => ESClient )(using Executor, Scheduler, lila.core.i18n.Translator): diff --git a/modules/gameSearch/src/main/GameSearchApi.scala b/modules/gameSearch/src/main/GameSearchApi.scala index a4b9987c84403..131d82ddb17a4 100644 --- a/modules/gameSearch/src/main/GameSearchApi.scala +++ b/modules/gameSearch/src/main/GameSearchApi.scala @@ -9,7 +9,7 @@ import lila.search.* final class GameSearchApi( client: ESClient, gameRepo: GameRepo, - userRepo: lila.user.UserRepo + userApi: lila.core.user.UserApi )(using Executor, Scheduler) extends SearchReadApi[Game, Query]: @@ -22,7 +22,7 @@ final class GameSearchApi( client.count(query).dmap(_.value) def validateAccounts(query: Query, forMod: Boolean): Fu[Boolean] = - fuccess(forMod) >>| userRepo.containsDisabled(query.userIds).not + fuccess(forMod) >>| userApi.containsDisabled(query.userIds).not def store(game: Game) = storable(game).so: diff --git a/modules/gameSearch/src/main/UserGameSearch.scala b/modules/gameSearch/src/main/UserGameSearch.scala index 3c3676168f25a..1066df1a226b7 100644 --- a/modules/gameSearch/src/main/UserGameSearch.scala +++ b/modules/gameSearch/src/main/UserGameSearch.scala @@ -11,7 +11,7 @@ final class UserGameSearch( paginator: lila.search.PaginatorBuilder[Game, Query] )(using lila.core.i18n.Translator): - def apply(user: lila.user.User, page: Int)(using Request[?], FormBinding, Lang) = + def apply(user: User, page: Int)(using Request[?], FormBinding, Lang) = paginator( query = forms.search .bindFromRequest() diff --git a/modules/mod/src/main/ModNotifier.scala b/modules/mod/src/main/ModNotifier.scala index 99b782d2899af..93f1d17b8ebaf 100644 --- a/modules/mod/src/main/ModNotifier.scala +++ b/modules/mod/src/main/ModNotifier.scala @@ -18,6 +18,6 @@ final private class ModNotifier( .void } - def refund(user: lila.user.User, pt: PerfType, points: Int): Funit = + def refund(user: User, pt: PerfType, points: Int): Funit = given play.api.i18n.Lang = user.realLang | lila.core.i18n.defaultLang notifyApi.notifyOne(user, RatingRefund(perf = pt.trans, points)) diff --git a/modules/mod/src/main/RatingRefund.scala b/modules/mod/src/main/RatingRefund.scala index a05d0a324c039..10edbeeabd1a9 100644 --- a/modules/mod/src/main/RatingRefund.scala +++ b/modules/mod/src/main/RatingRefund.scala @@ -62,7 +62,7 @@ final private class RatingRefund( notifier.refund(victim.user, pt, points) def applyRefund(ref: Refund) = - userApi.withPerf(ref.victim, ref.perf).flatMapz { user => + userApi.byIdWithPerf(ref.victim, ref.perf).flatMapz { user => perfStat.highestRating(user.user.id, ref.perf).flatMap { highest => val points = pointsToRefund(ref, curRating = user.perf.intRating, highest = highest) (points > 0).so(refundPoints(user, ref.perf, points)) diff --git a/modules/perfStat/src/main/PerfStat.scala b/modules/perfStat/src/main/PerfStat.scala index a6d5c9b0b0bb2..7f863aeade875 100644 --- a/modules/perfStat/src/main/PerfStat.scala +++ b/modules/perfStat/src/main/PerfStat.scala @@ -37,7 +37,7 @@ case class PerfStat( object PerfStat: - type Getter = (lila.user.User, PerfType) => Fu[PerfStat] + type Getter = (User, PerfType) => Fu[PerfStat] def makeId(userId: UserId, perfType: PerfType) = s"$userId/${perfType.id}" diff --git a/modules/plan/src/main/PlanApi.scala b/modules/plan/src/main/PlanApi.scala index 931c014c9e0d3..d7a45b9ec99cd 100644 --- a/modules/plan/src/main/PlanApi.scala +++ b/modules/plan/src/main/PlanApi.scala @@ -291,7 +291,7 @@ final class PlanApi( def userSubscription(user: User): Fu[Option[PayPalSubscription]] = userSubscriptionId(user).flatMapz(payPalClient.getSubscription) - def createOrder(checkout: PlanCheckout, user: User, giftTo: Option[lila.user.User]) = + def createOrder(checkout: PlanCheckout, user: User, giftTo: Option[User]) = for isLifetime <- pricingApi.isLifetime(checkout.money) order <- payPalClient.createOrder(CreatePayPalOrder(checkout, user, giftTo, isLifetime)) diff --git a/modules/pool/src/main/Env.scala b/modules/pool/src/main/Env.scala index 63fdac6fb142b..adc74223abd5f 100644 --- a/modules/pool/src/main/Env.scala +++ b/modules/pool/src/main/Env.scala @@ -7,8 +7,7 @@ import lila.game.Game @Module final class Env( - userRepo: lila.user.UserRepo, - perfsRepo: lila.user.UserPerfsRepo, + userApi: lila.core.user.UserApi, gameRepo: lila.game.GameRepo, idGenerator: lila.game.IdGenerator, HasCurrentPlayban: lila.core.playban.HasCurrentPlayban, diff --git a/modules/pool/src/main/GameStarter.scala b/modules/pool/src/main/GameStarter.scala index 35c2360c03a2b..650dec5dbd37f 100644 --- a/modules/pool/src/main/GameStarter.scala +++ b/modules/pool/src/main/GameStarter.scala @@ -4,12 +4,10 @@ import chess.ByColor import lila.game.{ Game, GameRepo, IdGenerator, Player } -import lila.user.{ UserPerfsRepo, UserRepo } import lila.core.pool.{ Pairing, Pairings } final private class GameStarter( - userRepo: UserRepo, - perfsRepo: UserPerfsRepo, + userApi: lila.core.user.UserApi, gameRepo: GameRepo, idGenerator: IdGenerator, onStart: GameId => Unit @@ -27,7 +25,7 @@ final private class GameStarter( workQueue: val userIds = couples.flatMap(_.userIds) for - (perfs, ids) <- perfsRepo.perfOf(userIds, pool.perfType).zip(idGenerator.games(couples.size)) + (perfs, ids) <- userApi.perfOf(userIds, pool.perfType).zip(idGenerator.games(couples.size)) pairings <- couples.zip(ids).map((one(pool, perfs)).tupled).parallel yield lila.common.Bus.publish(Pairings(pairings.flatten.toList), "poolPairings") @@ -39,7 +37,7 @@ final private class GameStarter( (perfs.get(p1.userId), perfs.get(p2.userId)).tupled .soFu: (perf1, perf2) => for - p1White <- userRepo.firstGetsWhite(p1.userId, p2.userId) + p1White <- userApi.firstGetsWhite(p1.userId, p2.userId) (whitePerf, blackPerf) = if p1White then perf1 -> perf2 else perf2 -> perf1 (whiteMember, blackMember) = if p1White then p1 -> p2 else p2 -> p1 game = makeGame( diff --git a/modules/setup/src/main/Env.scala b/modules/setup/src/main/Env.scala index b551e5716c874..ebe7e7b6cc722 100644 --- a/modules/setup/src/main/Env.scala +++ b/modules/setup/src/main/Env.scala @@ -7,7 +7,7 @@ import play.api.Configuration final class Env( appConfig: Configuration, gameRepo: lila.game.GameRepo, - perfsRepo: lila.user.UserPerfsRepo, + userApi: lila.core.user.UserApi, onStart: lila.core.game.OnStart, gameCache: lila.game.Cached )(using Executor, akka.stream.Materializer, lila.game.IdGenerator): diff --git a/modules/setup/src/main/Processor.scala b/modules/setup/src/main/Processor.scala index 48716637b717f..d652219a930e3 100644 --- a/modules/setup/src/main/Processor.scala +++ b/modules/setup/src/main/Processor.scala @@ -4,25 +4,24 @@ import lila.common.Bus import lila.game.{ GameRepo, IdGenerator, Pov } import lila.lobby.Seek import lila.lobby.{ AddHook, AddSeek } -import lila.user.{ Me, User, UserPerfsRepo } import lila.core.perf.UserWithPerfs final private[setup] class Processor( gameCache: lila.game.Cached, gameRepo: GameRepo, - perfsRepo: UserPerfsRepo, + userApi: lila.core.user.UserApi, onStart: lila.core.game.OnStart )(using Executor, IdGenerator): def ai(config: AiConfig)(using me: Option[Me]): Fu[Pov] = for - me <- me.map(_.value).soFu(perfsRepo.withPerf(_, config.perfType)) + me <- me.map(_.value).soFu(userApi.withPerf(_, config.perfType)) pov <- config.pov(me) _ <- gameRepo.insertDenormalized(pov.game) _ = onStart(pov.gameId) yield pov def apiAi(config: ApiAiConfig)(using me: Me): Fu[Pov] = for - me <- perfsRepo.withPerf(me, config.perfType) + me <- userApi.withPerf(me, config.perfType) pov <- config.pov(me.some) _ <- gameRepo.insertDenormalized(pov.game) _ = onStart(pov.gameId) diff --git a/modules/tournament/src/main/TournamentRepo.scala b/modules/tournament/src/main/TournamentRepo.scala index aeefe972a563d..b998ecffcda20 100644 --- a/modules/tournament/src/main/TournamentRepo.scala +++ b/modules/tournament/src/main/TournamentRepo.scala @@ -327,7 +327,7 @@ final class TournamentRepo(val coll: Coll, playerCollName: CollName)(using Execu .list(500) private[tournament] def sortedCursor( - owner: lila.user.User, + owner: User, status: List[Status], batchSize: Int, readPref: ReadPref = _.priTemp diff --git a/modules/tv/src/main/Env.scala b/modules/tv/src/main/Env.scala index 431bdbee668e8..69aae8033822c 100644 --- a/modules/tv/src/main/Env.scala +++ b/modules/tv/src/main/Env.scala @@ -8,7 +8,7 @@ import lila.tv.Tv.Channel @Module final class Env( gameRepo: lila.game.GameRepo, - lightUserApi: lila.user.LightUserApi, + lightUserApi: lila.core.user.LightUserApi, lightUserSync: lila.core.LightUser.GetterSync, gameProxy: lila.game.core.GameProxy, system: ActorSystem, diff --git a/modules/tv/src/main/TvSyncActor.scala b/modules/tv/src/main/TvSyncActor.scala index 80bce931d747b..93a5d49025fb1 100644 --- a/modules/tv/src/main/TvSyncActor.scala +++ b/modules/tv/src/main/TvSyncActor.scala @@ -8,7 +8,7 @@ import lila.common.Json.given import lila.game.{ Game, Pov } final private[tv] class TvSyncActor( - lightUserApi: lila.user.LightUserApi, + lightUserApi: lila.core.user.LightUserApi, onTvGame: lila.game.core.OnTvGame, gameProxy: lila.game.core.GameProxy, rematches: lila.game.Rematches diff --git a/modules/user/src/main/UserApi.scala b/modules/user/src/main/UserApi.scala index c3272d0c42f26..481cafe7546b5 100644 --- a/modules/user/src/main/UserApi.scala +++ b/modules/user/src/main/UserApi.scala @@ -44,9 +44,10 @@ final class UserApi(userRepo: UserRepo, perfsRepo: UserPerfsRepo, cacheApi: Cach countEngines, firstGetsWhite, incColor, - userIdsWithRoles + userIdsWithRoles, + containsDisabled } - export perfsRepo.{ perfsOf, setPerf, dubiousPuzzle, glicko } + export perfsRepo.{ perfOf, perfsOf, setPerf, dubiousPuzzle, glicko, withPerf } export gamePlayers.{ apply as gamePlayersAny, loggedIn as gamePlayersLoggedIn } // hit by game rounds @@ -102,7 +103,7 @@ final class UserApi(userRepo: UserRepo, perfsRepo: UserPerfsRepo, cacheApi: Cach yield UserWithPerfs(user, perfs) def enabledWithPerf[U: UserIdOf](id: U, perfType: PerfType): Fu[Option[WithPerf]] = - withPerf(id, perfType).dmap(_.filter(_.user.enabled.yes)) + byIdWithPerf(id, perfType).dmap(_.filter(_.user.enabled.yes)) def listWithPerfs[U: UserIdOf](us: List[U]): Fu[List[UserWithPerfs]] = us.nonEmpty.so: @@ -122,8 +123,8 @@ final class UserApi(userRepo: UserRepo, perfsRepo: UserPerfsRepo, cacheApi: Cach perfs = perfsRepo.aggregate.readFirst(doc, user) yield UserWithPerfs(user, perfs) - def withPerf[U: UserIdOf](id: U, pt: PerfType): Fu[Option[WithPerf]] = - userRepo.byId(id).flatMapz(perfsRepo.withPerf(_, pt).dmap(some)) + def byIdWithPerf[U: UserIdOf](id: U, pk: PerfKey): Fu[Option[WithPerf]] = + userRepo.byId(id).flatMapz(perfsRepo.withPerf(_, pk).dmap(some)) def pairWithPerfs(userIds: ByColor[Option[UserId]]): Fu[ByColor[Option[UserWithPerfs]]] = listWithPerfs(userIds.flatten).map: users =>