From 8b3f0121fb85b830811e627ae0439a436e693802 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 11 Apr 2024 19:52:58 +0200 Subject: [PATCH] remove more deps to pref --- app/templating/SetupHelper.scala | 6 +++--- build.sbt | 4 ++-- modules/core/src/main/pref.scala | 7 +++++++ modules/forum/src/main/Env.scala | 3 +-- modules/forum/src/main/MentionNotifier.scala | 2 +- modules/insight/src/main/Env.scala | 2 +- modules/insight/src/main/Share.scala | 16 +++++++--------- modules/pref/src/main/Pref.scala | 6 ++---- modules/pref/src/main/PrefApi.scala | 5 +++-- 9 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/templating/SetupHelper.scala b/app/templating/SetupHelper.scala index 6f915a8ece5e4..62186b7640935 100644 --- a/app/templating/SetupHelper.scala +++ b/app/templating/SetupHelper.scala @@ -305,9 +305,9 @@ trait SetupHelper: def translatedInsightShareChoices(using Translate) = List( - (Pref.InsightShare.NOBODY, trans.site.withNobody.txt()), - (Pref.InsightShare.FRIENDS, trans.site.withFriends.txt()), - (Pref.InsightShare.EVERYBODY, trans.site.withEverybody.txt()) + (lila.core.pref.InsightShare.NOBODY, trans.site.withNobody.txt()), + (lila.core.pref.InsightShare.FRIENDS, trans.site.withFriends.txt()), + (lila.core.pref.InsightShare.EVERYBODY, trans.site.withEverybody.txt()) ) def translatedBoardResizeHandleChoices(using Translate) = diff --git a/build.sbt b/build.sbt index d4821b644935b..b15b822a29222 100644 --- a/build.sbt +++ b/build.sbt @@ -275,7 +275,7 @@ lazy val importer = module("importer", ) lazy val insight = module("insight", - Seq(analyse, pref), + Seq(analyse), Seq(scalatags) ++ reactivemongo.bundle ) @@ -415,7 +415,7 @@ lazy val msg = module("msg", ) lazy val forum = module("forum", - Seq(user, pref, pref), + Seq(user), reactivemongo.bundle ) diff --git a/modules/core/src/main/pref.scala b/modules/core/src/main/pref.scala index a3a0f98248fb6..5964f47593e7e 100644 --- a/modules/core/src/main/pref.scala +++ b/modules/core/src/main/pref.scala @@ -22,8 +22,15 @@ trait Pref: trait PrefApi: def followable(userId: UserId): Fu[Boolean] def getMessage(userId: UserId): Fu[Int] + def getInsightShare(userId: UserId): Future[Int] + def mentionableIds(userIds: Set[UserId]): Fu[Set[UserId]] object Message: val NEVER = 1 val FRIEND = 2 val ALWAYS = 3 + +object InsightShare: + val NOBODY = 0 + val FRIENDS = 1 + val EVERYBODY = 2 diff --git a/modules/forum/src/main/Env.scala b/modules/forum/src/main/Env.scala index 673e42b32b05e..eaeda3f2041e4 100644 --- a/modules/forum/src/main/Env.scala +++ b/modules/forum/src/main/Env.scala @@ -6,7 +6,6 @@ import play.api.libs.ws.StandaloneWSClient import lila.common.autoconfig.{ *, given } import lila.core.config.* -import lila.pref.PrefApi import lila.core.relation.RelationApi import lila.user.User import lila.core.forum.ForumPostMiniView @@ -27,7 +26,7 @@ final class Env( shutupApi: lila.core.shutup.ShutupApi, notifyApi: lila.core.notify.NotifyApi, relationApi: RelationApi, - prefApi: PrefApi, + prefApi: lila.core.pref.PrefApi, modLog: lila.core.mod.LogApi, userRepo: lila.user.UserRepo, cacheApi: lila.memo.CacheApi, diff --git a/modules/forum/src/main/MentionNotifier.scala b/modules/forum/src/main/MentionNotifier.scala index be6a7b07e173d..b17a9235af7b6 100644 --- a/modules/forum/src/main/MentionNotifier.scala +++ b/modules/forum/src/main/MentionNotifier.scala @@ -7,7 +7,7 @@ final class MentionNotifier( userRepo: lila.user.UserRepo, notifyApi: NotifyApi, relationApi: lila.core.relation.RelationApi, - prefApi: lila.pref.PrefApi + prefApi: lila.core.pref.PrefApi )(using Executor): def notifyMentionedUsers(post: ForumPost, topic: ForumTopic): Funit = diff --git a/modules/insight/src/main/Env.scala b/modules/insight/src/main/Env.scala index 2fd734d4ca09c..818c2722da3b7 100644 --- a/modules/insight/src/main/Env.scala +++ b/modules/insight/src/main/Env.scala @@ -11,7 +11,7 @@ final class Env( appConfig: Configuration, gameRepo: lila.game.GameRepo, analysisRepo: lila.analyse.AnalysisRepo, - prefApi: lila.pref.PrefApi, + prefApi: lila.core.pref.PrefApi, relationApi: lila.core.relation.RelationApi, cacheApi: lila.memo.CacheApi, mongo: lila.db.Env diff --git a/modules/insight/src/main/Share.scala b/modules/insight/src/main/Share.scala index 21ea0bf31a24a..82cc1d06db9f2 100644 --- a/modules/insight/src/main/Share.scala +++ b/modules/insight/src/main/Share.scala @@ -1,24 +1,22 @@ package lila.insight -import lila.pref.Pref import lila.core.perm.{ Granter, Grantable } import lila.core.user.User final class Share( - prefApi: lila.pref.PrefApi, + prefApi: lila.core.pref.PrefApi, relationApi: lila.core.relation.RelationApi )(using Executor): - def getPrefId(insighted: User) = prefApi.get(insighted.id, _.insightShare) + def getPrefId(insighted: User) = prefApi.getInsightShare(insighted.id) def grant(insighted: User)(using to: Option[User]): Fu[Boolean] = if to.soUse(Granter[User](_.SeeInsight)) then fuTrue else - getPrefId(insighted).flatMap { - case _ if to.contains(insighted) => fuTrue - case Pref.InsightShare.EVERYBODY => fuTrue - case Pref.InsightShare.FRIENDS => + getPrefId(insighted).flatMap: + case _ if to.contains(insighted) => fuTrue + case lila.core.pref.InsightShare.EVERYBODY => fuTrue + case lila.core.pref.InsightShare.FRIENDS => to.so: t => relationApi.fetchAreFriends(insighted.id, t.id) - case Pref.InsightShare.NOBODY => fuFalse - } + case lila.core.pref.InsightShare.NOBODY => fuFalse diff --git a/modules/pref/src/main/Pref.scala b/modules/pref/src/main/Pref.scala index e2bc23f2dc769..6f11a7bd1a3b7 100644 --- a/modules/pref/src/main/Pref.scala +++ b/modules/pref/src/main/Pref.scala @@ -217,9 +217,7 @@ object Pref: object ConfirmResign extends BooleanPref object InsightShare: - val NOBODY = 0 - val FRIENDS = 1 - val EVERYBODY = 2 + import lila.core.pref.InsightShare.* val choices = Seq( NOBODY -> "With nobody", @@ -454,7 +452,7 @@ object Pref: studyInvite = StudyInvite.ALWAYS, submitMove = SubmitMove.CORRESPONDENCE, confirmResign = ConfirmResign.YES, - insightShare = InsightShare.FRIENDS, + insightShare = lila.core.pref.InsightShare.FRIENDS, keyboardMove = KeyboardMove.NO, voice = None, zen = Zen.NO, diff --git a/modules/pref/src/main/PrefApi.scala b/modules/pref/src/main/PrefApi.scala index f678aec7fd0ba..90f47ab2a5184 100644 --- a/modules/pref/src/main/PrefApi.scala +++ b/modules/pref/src/main/PrefApi.scala @@ -71,7 +71,8 @@ final class PrefApi( .map: opponent => myPov.fold(ByColor(myPref, opponent), ByColor(opponent, myPref)) - def getMessage(userId: UserId): Future[Int] = get(userId, _.message) + def getMessage(userId: UserId): Future[Int] = get(userId, _.message) + def getInsightShare(userId: UserId): Future[Int] = get(userId, _.insightShare) def followable(userId: UserId): Fu[Boolean] = coll.primitiveOne[Boolean]($id(userId), "follow").map(_ | Pref.default.follow) @@ -115,7 +116,7 @@ final class PrefApi( _.copy( takeback = Pref.Takeback.NEVER, moretime = Pref.Moretime.NEVER, - insightShare = Pref.InsightShare.EVERYBODY + insightShare = lila.core.pref.InsightShare.EVERYBODY ) )