Skip to content

Commit

Permalink
remove deps to pref
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Apr 11, 2024
1 parent 3699422 commit 80eff3b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions app/templating/SetupHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ trait SetupHelper:

def translatedMessageChoices(using Translate) =
List(
(Pref.Message.NEVER, trans.site.onlyExistingConversations.txt()),
(Pref.Message.FRIEND, trans.site.onlyFriends.txt()),
(Pref.Message.ALWAYS, trans.site.always.txt())
(lila.core.pref.Message.NEVER, trans.site.onlyExistingConversations.txt()),
(lila.core.pref.Message.FRIEND, trans.site.onlyFriends.txt()),
(lila.core.pref.Message.ALWAYS, trans.site.always.txt())
)

def translatedStudyInviteChoices(using Translate) = privacyBaseChoices
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ lazy val coach = module("coach",
)

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

Expand Down Expand Up @@ -400,7 +400,7 @@ lazy val plan = module("plan",
)

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

Expand Down
9 changes: 9 additions & 0 deletions modules/core/src/main/pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ trait Pref:
def showRatings: Boolean
def animationMillis: Int
def animationMillisForSpeedPuzzles: Int

trait PrefApi:
def followable(userId: UserId): Fu[Boolean]
def getMessage(userId: UserId): Fu[Int]

object Message:
val NEVER = 1
val FRIEND = 2
val ALWAYS = 3
2 changes: 1 addition & 1 deletion modules/msg/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Env(
userRepo: lila.user.UserRepo,
userCache: lila.user.Cached,
relationApi: lila.core.relation.RelationApi,
prefApi: lila.pref.PrefApi,
prefApi: lila.core.pref.PrefApi,
notifyApi: lila.core.notify.NotifyApi,
cacheApi: lila.memo.CacheApi,
reportApi: lila.core.report.ReportApi,
Expand Down
10 changes: 5 additions & 5 deletions modules/msg/src/main/MsgSecurity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import lila.core.report.SuspectId

final private class MsgSecurity(
colls: MsgColls,
prefApi: lila.pref.PrefApi,
prefApi: lila.core.pref.PrefApi,
userRepo: lila.user.UserRepo,
getBotUserIds: lila.user.GetBotIds,
relationApi: lila.core.relation.RelationApi,
Expand Down Expand Up @@ -152,10 +152,10 @@ final private class MsgSecurity(
}

private def create(contacts: User.Contacts): Fu[Boolean] =
prefApi.get(contacts.dest.id, _.message).flatMap {
case lila.pref.Pref.Message.NEVER => fuccess(false)
case lila.pref.Pref.Message.FRIEND => relationApi.fetchFollows(contacts.dest.id, contacts.orig.id)
case lila.pref.Pref.Message.ALWAYS => fuccess(true)
prefApi.getMessage(contacts.dest.id).flatMap {
case lila.core.pref.Message.NEVER => fuccess(false)
case lila.core.pref.Message.FRIEND => relationApi.fetchFollows(contacts.dest.id, contacts.orig.id)
case lila.core.pref.Message.ALWAYS => fuccess(true)
}

// Even if the dest prefs disallow it,
Expand Down
6 changes: 2 additions & 4 deletions modules/pref/src/main/Pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ object Pref:
)

object Message:
val NEVER = 1
val FRIEND = 2
val ALWAYS = 3
import lila.core.pref.Message.*

val choices = Seq(
NEVER -> "Only existing conversations",
Expand Down Expand Up @@ -452,7 +450,7 @@ object Pref:
replay = Replay.ALWAYS,
clockTenths = ClockTenths.LOWTIME,
challenge = Challenge.REGISTERED,
message = Message.ALWAYS,
message = lila.core.pref.Message.ALWAYS,
studyInvite = StudyInvite.ALWAYS,
submitMove = SubmitMove.CORRESPONDENCE,
confirmResign = ConfirmResign.YES,
Expand Down
6 changes: 5 additions & 1 deletion modules/pref/src/main/PrefApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import reactivemongo.api.bson.*
import lila.db.dsl.{ *, given }
import lila.memo.CacheApi.*
import lila.core.user.User
import lila.core.userId

final class PrefApi(
val coll: Coll,
cacheApi: lila.memo.CacheApi
)(using Executor):
)(using Executor)
extends lila.core.pref.PrefApi:

import PrefHandlers.given

Expand Down Expand Up @@ -69,6 +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 followable(userId: UserId): Fu[Boolean] =
coll.primitiveOne[Boolean]($id(userId), "follow").map(_ | Pref.default.follow)

Expand Down
4 changes: 2 additions & 2 deletions modules/relation/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ final class Env(
appConfig: Configuration,
db: lila.db.Db,
userRepo: lila.core.user.UserRepo,
userAPi: lila.core.user.UserApi,
prefApi: lila.pref.PrefApi,
userApi: lila.core.user.UserApi,
prefApi: lila.core.pref.PrefApi,
cacheApi: lila.memo.CacheApi
)(using Executor, ActorSystem, akka.stream.Materializer):

Expand Down
2 changes: 1 addition & 1 deletion modules/relation/src/main/RelationApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import lila.core.userId.UserSearch

final class RelationApi(
repo: RelationRepo,
prefApi: lila.pref.PrefApi,
prefApi: lila.core.pref.PrefApi,
cacheApi: lila.memo.CacheApi,
userApi: UserApi,
config: RelationConfig
Expand Down
1 change: 0 additions & 1 deletion modules/streamer/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ final class Env(
perfsRepo: lila.user.UserPerfsRepo,
userApi: lila.user.UserApi,
subsRepo: lila.core.relation.SubscriptionRepo,
prefApi: lila.pref.PrefApi,
db: lila.db.Db,
net: lila.core.config.NetConfig
)(using scheduler: Scheduler)(using Executor, akka.stream.Materializer):
Expand Down

0 comments on commit 80eff3b

Please sign in to comment.