Skip to content

Commit

Permalink
remove more deps to pref
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Apr 11, 2024
1 parent 80eff3b commit 8b3f012
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/templating/SetupHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ lazy val importer = module("importer",
)

lazy val insight = module("insight",
Seq(analyse, pref),
Seq(analyse),
Seq(scalatags) ++ reactivemongo.bundle
)

Expand Down Expand Up @@ -415,7 +415,7 @@ lazy val msg = module("msg",
)

lazy val forum = module("forum",
Seq(user, pref, pref),
Seq(user),
reactivemongo.bundle
)

Expand Down
7 changes: 7 additions & 0 deletions modules/core/src/main/pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions modules/forum/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion modules/forum/src/main/MentionNotifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion modules/insight/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions modules/insight/src/main/Share.scala
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions modules/pref/src/main/Pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions modules/pref/src/main/PrefApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
)

Expand Down

0 comments on commit 8b3f012

Please sign in to comment.