diff --git a/build.sbt b/build.sbt index a7519fbd64f6b..cb5b306184843 100644 --- a/build.sbt +++ b/build.sbt @@ -150,7 +150,7 @@ lazy val coach = module("coach", ) lazy val streamer = module("streamer", - Seq(user), + Seq(coreI18n, memo), reactivemongo.bundle ) diff --git a/modules/chat/src/main/ChatApi.scala b/modules/chat/src/main/ChatApi.scala index d80fc71b66fe5..beed3c27801ea 100644 --- a/modules/chat/src/main/ChatApi.scala +++ b/modules/chat/src/main/ChatApi.scala @@ -130,7 +130,7 @@ final class ChatApi( scope: ChatTimeout.Scope, text: String, busChan: BusChan.Select - )(using mod: Me.Id): Funit = + )(using mod: MyId): Funit = coll.byId[UserChat](chatId.value).zip(userRepo.me(mod)).zip(userRepo.byId(userId)).flatMap { case ((Some(chat), Some(me)), Some(user)) if isMod(using me) || (busChan(BusChan) == BusChan.study && isRelayMod(using me)) || diff --git a/modules/core/src/main/user.scala b/modules/core/src/main/user.scala index 0901af647c6c9..cdcc4c6b2c66c 100644 --- a/modules/core/src/main/user.scala +++ b/modules/core/src/main/user.scala @@ -184,6 +184,7 @@ case class ChangeEmail(id: UserId, email: EmailAddress) trait UserApi: def byId[U: UserIdOf](u: U): Fu[Option[User]] + def byIds[U: UserIdOf](us: Iterable[U]): Fu[List[User]] def email(id: UserId): Fu[Option[EmailAddress]] def withEmails[U: UserIdOf](user: U): Fu[Option[WithEmails]] def pair(x: UserId, y: UserId): Fu[Option[(User, User)]] @@ -242,7 +243,9 @@ object UserMarks extends TotalWrapper[UserMarks, List[UserMark]]: def arenaBan: Boolean = hasMark(UserMark.arenaban) def alt: Boolean = hasMark(UserMark.alt) -abstract class UserRepo(val coll: reactivemongo.api.bson.collection.BSONCollection) +abstract class UserRepo(val coll: reactivemongo.api.bson.collection.BSONCollection): + given userHandler: reactivemongo.api.bson.BSONDocumentHandler[User] + object BSONFields: val enabled = "enabled" val title = "title" diff --git a/modules/irwin/src/main/IrwinApi.scala b/modules/irwin/src/main/IrwinApi.scala index a9e1b6ca8ebba..2142066b7fa31 100644 --- a/modules/irwin/src/main/IrwinApi.scala +++ b/modules/irwin/src/main/IrwinApi.scala @@ -148,7 +148,7 @@ final class IrwinApi( private var subs = Map.empty[SuspectId, Set[ModId]] - def add(suspectId: SuspectId)(using me: Me.Id): Unit = + def add(suspectId: SuspectId)(using me: MyId): Unit = subs = subs.updated(suspectId, ~subs.get(suspectId) + me.modId) private[IrwinApi] def apply(report: IrwinReport): Funit = diff --git a/modules/lobby/src/main/LobbySocket.scala b/modules/lobby/src/main/LobbySocket.scala index d633bed12fc68..19777169a4e0a 100644 --- a/modules/lobby/src/main/LobbySocket.scala +++ b/modules/lobby/src/main/LobbySocket.scala @@ -205,7 +205,7 @@ final class LobbySocket( ratingRange = ratingRange, lame = user.lame, blocking = user.blocking.map(_ ++ blocking) - )(using user.id.into(Me.Id)) + )(using user.id.into(MyId)) ) } } diff --git a/modules/mod/src/main/Env.scala b/modules/mod/src/main/Env.scala index 9dfdcaf6111db..7eca8e5aa56f7 100644 --- a/modules/mod/src/main/Env.scala +++ b/modules/mod/src/main/Env.scala @@ -104,7 +104,7 @@ final class Env( api.autoMark(SuspectId(suspectId), s"Self report: ${name}")(using UserId.lichessAsMe) }, "chatTimeout" -> { case lila.core.mod.ChatTimeout(mod, user, reason, text) => - logApi.chatTimeout(user, reason, text)(using mod.into(Me.Id)) + logApi.chatTimeout(user, reason, text)(using mod.into(MyId)) }, "loginWithWeakPassword" -> { case u: User => logApi.loginWithWeakPassword(u.id) }, "loginWithBlankedPassword" -> { case u: User => logApi.loginWithBlankedPassword(u.id) }, diff --git a/modules/mod/src/main/ModApi.scala b/modules/mod/src/main/ModApi.scala index 35d761293c4c3..ad20ad5b536a8 100644 --- a/modules/mod/src/main/ModApi.scala +++ b/modules/mod/src/main/ModApi.scala @@ -26,14 +26,14 @@ final class ModApi( if v then sel(UserMark) :: a.value else a.value.filter(sel(UserMark) !=) - def setAlt(prev: Suspect, v: Boolean)(using me: Me.Id): Funit = + def setAlt(prev: Suspect, v: Boolean)(using me: MyId): Funit = for _ <- userRepo.setAlt(prev.user.id, v) sus = prev.set(_.withMarks(_.set(_.alt, v))) _ <- logApi.alt(sus, v) yield if v then notifier.reporters(me.modId, sus) - def setEngine(prev: Suspect, v: Boolean)(using me: Me.Id): Funit = + def setEngine(prev: Suspect, v: Boolean)(using me: MyId): Funit = (prev.user.marks.engine != v).so { for _ <- userRepo.setEngine(prev.user.id, v) @@ -46,7 +46,7 @@ final class ModApi( refunder.schedule(sus) } - def autoMark(suspectId: SuspectId, note: String)(using Me.Id): Funit = + def autoMark(suspectId: SuspectId, note: String)(using MyId): Funit = for sus <- reportApi.getSuspect(suspectId.value).orFail(s"No such suspect $suspectId") unengined <- logApi.wasUnengined(sus) @@ -72,7 +72,7 @@ final class ModApi( notifier.reporters(me.modId, sus) sus - def setTroll(prev: Suspect, value: Boolean)(using me: Me.Id): Fu[Suspect] = + def setTroll(prev: Suspect, value: Boolean)(using me: MyId): Fu[Suspect] = val changed = value != prev.user.marks.troll val sus = prev.set(_.withMarks(_.set(_.troll, value))) changed @@ -86,13 +86,13 @@ final class ModApi( .inject(sus) def autoTroll(sus: Suspect, note: String): Funit = - given Me.Id = UserId.lichessAsMe + given MyId = UserId.lichessAsMe setTroll(sus, true) >> noteApi.lichessWrite(sus.user, note) >> reportApi.autoProcess(sus, Set(Room.Comm)) def garbageCollect(userId: UserId): Funit = - given Me.Id = UserId.lichessAsMe + given MyId = UserId.lichessAsMe for sus <- reportApi.getSuspect(userId).orFail(s"No such suspect $userId") _ <- setAlt(sus, v = true) @@ -150,23 +150,23 @@ final class ModApi( lila.security.Permission.diff(Permission(user), finalPermissions) ) - def setReportban(sus: Suspect, v: Boolean)(using Me.Id): Funit = + def setReportban(sus: Suspect, v: Boolean)(using MyId): Funit = (sus.user.marks.reportban != v).so { userRepo.setReportban(sus.user.id, v) >> logApi.reportban(sus, v) } - def setRankban(sus: Suspect, v: Boolean)(using Me.Id): Funit = + def setRankban(sus: Suspect, v: Boolean)(using MyId): Funit = (sus.user.marks.rankban != v).so { if v then Bus.publish(lila.core.mod.KickFromRankings(sus.user.id), "kickFromRankings") userRepo.setRankban(sus.user.id, v) >> logApi.rankban(sus, v) } - def setArenaBan(sus: Suspect, v: Boolean)(using Me.Id): Funit = + def setArenaBan(sus: Suspect, v: Boolean)(using MyId): Funit = (sus.user.marks.arenaBan != v).so { userRepo.setArenaBan(sus.user.id, v) >> logApi.arenaBan(sus, v) } - def setPrizeban(sus: Suspect, v: Boolean)(using Me.Id): Funit = + def setPrizeban(sus: Suspect, v: Boolean)(using MyId): Funit = (sus.user.marks.prizeban != v).so { userRepo.setPrizeban(sus.user.id, v) >> logApi.prizeban(sus, v) } diff --git a/modules/mod/src/main/Modlog.scala b/modules/mod/src/main/Modlog.scala index dc01b24ba55eb..c19bc5a73f391 100644 --- a/modules/mod/src/main/Modlog.scala +++ b/modules/mod/src/main/Modlog.scala @@ -87,13 +87,13 @@ case class Modlog( object Modlog: - def apply(user: Option[UserId], action: String, details: Option[String])(using me: Me.Id): Modlog = + def apply(user: Option[UserId], action: String, details: Option[String])(using me: MyId): Modlog = Modlog(me.modId, user, action, details) - def apply(user: Option[UserId], action: String)(using me: Me.Id): Modlog = + def apply(user: Option[UserId], action: String)(using me: MyId): Modlog = Modlog(me.modId, user, action, none) - def make(sus: Suspect, action: String, details: Option[String] = None)(using me: Me.Id): Modlog = + def make(sus: Suspect, action: String, details: Option[String] = None)(using me: MyId): Modlog = Modlog( mod = me.modId, user = sus.user.id.some, diff --git a/modules/mod/src/main/ModlogApi.scala b/modules/mod/src/main/ModlogApi.scala index 33ecfd320be41..81ba7bef12dc2 100644 --- a/modules/mod/src/main/ModlogApi.scala +++ b/modules/mod/src/main/ModlogApi.scala @@ -23,37 +23,37 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres private val markActions = List(Modlog.alt, Modlog.booster, Modlog.closeAccount, Modlog.engine, Modlog.troll) - def streamerDecline(streamerId: UserId)(using Me.Id) = add: + def streamerDecline(streamerId: UserId)(using MyId) = add: Modlog(streamerId.some, Modlog.streamerDecline) - def streamerList(streamerId: UserId, v: Boolean)(using Me.Id) = add: + def streamerList(streamerId: UserId, v: Boolean)(using MyId) = add: Modlog(streamerId.some, if v then Modlog.streamerList else Modlog.streamerUnlist) - def streamerTier(streamerId: UserId, v: Int)(using Me.Id) = add: + def streamerTier(streamerId: UserId, v: Int)(using MyId) = add: Modlog(streamerId.some, Modlog.streamerTier, v.toString.some) - def blogTier(sus: Suspect, tier: String)(using Me.Id) = add: + def blogTier(sus: Suspect, tier: String)(using MyId) = add: Modlog.make(sus, Modlog.blogTier, tier.some) - def blogPostEdit(sus: Suspect, postId: UblogPostId, postName: String, action: String)(using Me.Id) = add: + def blogPostEdit(sus: Suspect, postId: UblogPostId, postName: String, action: String)(using MyId) = add: Modlog.make(sus, Modlog.blogPostEdit, s"$action #$postId $postName".some) - def practiceConfig(using Me.Id) = add: + def practiceConfig(using MyId) = add: Modlog(none, Modlog.practiceConfig) - def alt(sus: Suspect, v: Boolean)(using Me.Id) = add: + def alt(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.alt else Modlog.unalt) - def engine(sus: Suspect, v: Boolean)(using Me.Id) = add: + def engine(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.engine else Modlog.unengine) - def booster(sus: Suspect, v: Boolean)(using Me.Id) = add: + def booster(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.booster else Modlog.unbooster) - def troll(sus: Suspect)(using Me.Id) = add: + def troll(sus: Suspect)(using MyId) = add: Modlog.make(sus, if sus.user.marks.troll then Modlog.troll else Modlog.untroll) - def fullCommExport(sus: Suspect)(using Me.Id) = add: + def fullCommExport(sus: Suspect)(using MyId) = add: Modlog.make(sus, Modlog.fullCommsExport) def setKidMode(mod: ModId, kid: UserId) = add: @@ -94,21 +94,21 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres def setEmail(user: UserId)(using Me) = add: Modlog(user.some, Modlog.setEmail) - def deletePost(user: Option[UserId], text: String)(using Me.Id) = add: + def deletePost(user: Option[UserId], text: String)(using MyId) = add: Modlog( user, Modlog.deletePost, details = Some(text.take(400)) ) - def toggleCloseTopic(categ: ForumCategId, topicSlug: String, closed: Boolean)(using Me.Id) = add: + def toggleCloseTopic(categ: ForumCategId, topicSlug: String, closed: Boolean)(using MyId) = add: Modlog( none, if closed then Modlog.closeTopic else Modlog.openTopic, details = s"$categ/$topicSlug".some ) - def toggleStickyTopic(categ: ForumCategId, topicSlug: String, sticky: Boolean)(using Me.Id) = add: + def toggleStickyTopic(categ: ForumCategId, topicSlug: String, sticky: Boolean)(using MyId) = add: Modlog( none, if sticky then Modlog.stickyTopic else Modlog.unstickyTopic, @@ -122,21 +122,21 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres postId: ForumPostId, text: String, edit: Boolean - )(using Me.Id) = add: + )(using MyId) = add: Modlog( none, if edit then Modlog.editAsAnonMod else Modlog.postAsAnonMod, details = s"$categ/$topic id: $postId ${text.take(400)}".some ) - def deleteTeam(id: String, explain: String)(using Me.Id) = add: + def deleteTeam(id: String, explain: String)(using MyId) = add: Modlog( none, Modlog.deleteTeam, details = s"$id: ${explain.take(200)}".some ).indexAs("team") - def toggleTeam(id: String, closing: Boolean, explain: String)(using Me.Id) = add: + def toggleTeam(id: String, closing: Boolean, explain: String)(using MyId) = add: Modlog( none, if closing then Modlog.disableTeam else Modlog.enableTeam, @@ -153,7 +153,7 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres def terminateTournament(name: String)(using Me) = add: Modlog(none, Modlog.terminateTournament, details = name.some) - def chatTimeout(user: UserId, reason: String, text: String)(using Me.Id) = add: + def chatTimeout(user: UserId, reason: String, text: String)(using MyId) = add: Modlog(user.some, Modlog.chatTimeout, details = s"$reason: $text".some) def setPermissions(user: UserId, permissions: Map[Permission, Boolean])(using Me) = add: @@ -189,13 +189,13 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres _.sec ) - def reportban(sus: Suspect, v: Boolean)(using Me.Id) = add: + def reportban(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.reportban else Modlog.unreportban) - def modMessage(user: UserId, subject: String)(using Me.Id) = add: + def modMessage(user: UserId, subject: String)(using MyId) = add: Modlog(user.some, Modlog.modMessage, details = subject.some) - def coachReview(coach: UserId, author: UserId)(using Me.Id) = add: + def coachReview(coach: UserId, author: UserId)(using MyId) = add: Modlog(coach.some, Modlog.coachReview, details = s"by $author".some) def cheatDetected(user: UserId, gameId: GameId) = add: @@ -206,25 +206,25 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres _ <- cheatDetected(user, gameId) yield prevCount + 1 - def cli(command: String)(using by: Me.Id) = add: + def cli(command: String)(using by: MyId) = add: Modlog(none, Modlog.cli, command.some) - def garbageCollect(sus: Suspect)(using Me.Id) = add: + def garbageCollect(sus: Suspect)(using MyId) = add: Modlog.make(sus, Modlog.garbageCollect) - def rankban(sus: Suspect, v: Boolean)(using Me.Id) = add: + def rankban(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.rankban else Modlog.unrankban) - def arenaBan(sus: Suspect, v: Boolean)(using Me.Id) = add: + def arenaBan(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.arenaBan else Modlog.unArenaBan) - def prizeban(sus: Suspect, v: Boolean)(using Me.Id) = add: + def prizeban(sus: Suspect, v: Boolean)(using MyId) = add: Modlog.make(sus, if v then Modlog.prizeban else Modlog.unprizeban) - def teamKick(user: UserId, teamName: String)(using Me.Id) = add: + def teamKick(user: UserId, teamName: String)(using MyId) = add: Modlog(user.some, Modlog.teamKick, details = Some(teamName.take(140))) - def teamEdit(teamOwner: UserId, teamName: String)(using Me.Id) = add: + def teamEdit(teamOwner: UserId, teamName: String)(using MyId) = add: Modlog(teamOwner.some, Modlog.teamEdit, details = Some(teamName.take(140))) def appealPost(user: UserId)(using me: Me) = add: @@ -322,7 +322,7 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres private def zulipMonitor(m: Modlog): Funit = import lila.mod.{ Modlog as M } - given Me.Id = m.mod.into(Me.Id) + given MyId = m.mod.into(MyId) val icon = m.action match case M.alt | M.arenaBan | M.engine | M.booster | M.troll | M.closeAccount => "thorhammer" case M.unalt | M.unArenaBan | M.unengine | M.unbooster | M.untroll | M.reopenAccount => "blue_circle" diff --git a/modules/report/src/main/ModReportFilter.scala b/modules/report/src/main/ModReportFilter.scala index 3951caa535278..cc0bc5d7f1778 100644 --- a/modules/report/src/main/ModReportFilter.scala +++ b/modules/report/src/main/ModReportFilter.scala @@ -5,7 +5,7 @@ import lila.user.{ Me, given } final class ModReportFilter: // mutable storage, because I cba to put it in DB - private var modIdFilter = Map.empty[Me.Id, Option[Room]] + private var modIdFilter = Map.empty[MyId, Option[Room]] def get(mod: Me): Option[Room] = modIdFilter.get(mod).flatten diff --git a/modules/report/src/main/ReportApi.scala b/modules/report/src/main/ReportApi.scala index 0e8cf9396b0af..87ff20ec5e838 100644 --- a/modules/report/src/main/ReportApi.scala +++ b/modules/report/src/main/ReportApi.scala @@ -106,7 +106,7 @@ final class ReportApi( (candidate.isAutomatic && candidate.isOther && candidate.suspect.user.marks.troll) || (candidate.isComm && candidate.suspect.user.marks.troll) - def getMyMod(using me: Me.Id): Fu[Option[Mod]] = userRepo.byId(me).dmap2(Mod.apply) + def getMyMod(using me: MyId): Fu[Option[Mod]] = userRepo.byId(me).dmap2(Mod.apply) def getMod[U: UserIdOf](u: U): Fu[Option[Mod]] = userRepo.byId(u).dmap2(Mod.apply) def getSuspect[U: UserIdOf](u: U): Fu[Option[Suspect]] = userRepo.byId(u).dmap2(Suspect.apply) @@ -288,7 +288,7 @@ final class ReportApi( maxScoreCache.invalidateUnit() lila.mon.mod.report.close.increment() - def autoProcess(sus: Suspect, rooms: Set[Room])(using Me.Id): Funit = + def autoProcess(sus: Suspect, rooms: Set[Room])(using MyId): Funit = val selector = $doc( "user" -> sus.user.id, "room".$in(rooms), @@ -298,7 +298,7 @@ final class ReportApi( .andDo(maxScoreCache.invalidateUnit()) .andDo(lila.mon.mod.report.close.increment()) - private def doProcessReport(selector: Bdoc, unsetInquiry: Boolean)(using me: Me.Id): Funit = + private def doProcessReport(selector: Bdoc, unsetInquiry: Boolean)(using me: MyId): Funit = coll.update .one( selector, diff --git a/modules/round/src/main/Messenger.scala b/modules/round/src/main/Messenger.scala index eed9605453f01..ac5227dc6d015 100644 --- a/modules/round/src/main/Messenger.scala +++ b/modules/round/src/main/Messenger.scala @@ -41,7 +41,7 @@ final class Messenger(api: ChatApi): (game.fromFriend || presets.contains(text)) .so(api.playerChat.write(game.id.into(ChatId), anonColor, text, _.round)) - def timeout(chatId: ChatId, suspect: UserId, reason: String, text: String)(using mod: Me.Id): Funit = + def timeout(chatId: ChatId, suspect: UserId, reason: String, text: String)(using mod: MyId): Funit = ChatTimeout .Reason(reason) .so: r => diff --git a/modules/streamer/src/main/Env.scala b/modules/streamer/src/main/Env.scala index 802aff641427c..47ef2ac253f4e 100644 --- a/modules/streamer/src/main/Env.scala +++ b/modules/streamer/src/main/Env.scala @@ -28,9 +28,8 @@ final class Env( cacheApi: lila.memo.CacheApi, picfitApi: lila.memo.PicfitApi, notifyApi: lila.core.notify.NotifyApi, - userRepo: lila.user.UserRepo, - perfsRepo: lila.user.UserPerfsRepo, - userApi: lila.user.UserApi, + userRepo: lila.core.user.UserRepo, + userApi: lila.core.user.UserApi, subsRepo: lila.core.relation.SubscriptionRepo, db: lila.db.Db, net: lila.core.config.NetConfig diff --git a/modules/streamer/src/main/LiveStream.scala b/modules/streamer/src/main/LiveStream.scala index 97b6c91d4090c..b306fcc8d3d17 100644 --- a/modules/streamer/src/main/LiveStream.scala +++ b/modules/streamer/src/main/LiveStream.scala @@ -24,7 +24,7 @@ case class LiveStreams(streams: List[Stream]): case (selected, _) => selected .toList - def withTitles(lightUser: lila.user.LightUserApi) = + def withTitles(lightUser: lila.core.user.LightUserApi) = LiveStreams.WithTitles( this, streams.view diff --git a/modules/streamer/src/main/StreamerApi.scala b/modules/streamer/src/main/StreamerApi.scala index e2a049a41b542..29b9427ed4bd2 100644 --- a/modules/streamer/src/main/StreamerApi.scala +++ b/modules/streamer/src/main/StreamerApi.scala @@ -3,12 +3,10 @@ import lila.common.Icon import lila.db.dsl.{ *, given } import lila.memo.CacheApi.* import lila.memo.PicfitApi -import lila.user.{ Me, User, UserApi, UserRepo } final class StreamerApi( coll: Coll, - userRepo: UserRepo, - userApi: UserApi, + userApi: lila.core.user.UserApi, cacheApi: lila.memo.CacheApi, picfitApi: PicfitApi, notifyApi: lila.core.notify.NotifyApi, @@ -24,7 +22,7 @@ final class StreamerApi( def byIds(ids: Iterable[Streamer.Id]): Fu[List[Streamer]] = coll.byIds[Streamer, Streamer.Id](ids) def find(username: UserStr): Fu[Option[Streamer.WithUser]] = - userRepo.byId(username).flatMapz(find) + userApi.byId(username).flatMapz(find) def find(user: User): Fu[Option[Streamer.WithUser]] = byId(user.id.into(Streamer.Id)).mapz: streamer => @@ -35,13 +33,13 @@ final class StreamerApi( val s = Streamer.WithUser(Streamer.make(user), user) coll.insert.one(s.streamer).inject(s.some) - def forSubscriber(streamerName: UserStr)(using me: Option[Me.Id]): Fu[Option[Streamer.WithContext]] = + def forSubscriber(streamerName: UserStr)(using me: Option[MyId]): Fu[Option[Streamer.WithContext]] = me.foldLeft(find(streamerName)): (streamerFu, me) => streamerFu.flatMapz: s => subsRepo.isSubscribed(me.id, s.streamer).map { sub => s.copy(subscribed = sub).some } - def withUsers(live: LiveStreams)(using me: Option[Me.Id]): Fu[List[Streamer.WithUserAndStream]] = for - users <- userRepo.byIds(live.streams.map(_.streamer.userId)) + def withUsers(live: LiveStreams)(using me: Option[MyId]): Fu[List[Streamer.WithUserAndStream]] = for + users <- userApi.byIds(live.streams.map(_.streamer.userId)) subs <- me.so(subsRepo.filterSubscribed(_, users.map(_.id))) yield live.streams.flatMap: s => users.find(_.is(s.streamer)).map { diff --git a/modules/streamer/src/main/StreamerPager.scala b/modules/streamer/src/main/StreamerPager.scala index a0b0218ce6536..a33fc4cb2fc61 100644 --- a/modules/streamer/src/main/StreamerPager.scala +++ b/modules/streamer/src/main/StreamerPager.scala @@ -4,12 +4,10 @@ import reactivemongo.api.* import scalalib.paginator.{ AdapterLike, Paginator } import lila.db.dsl.{ *, given } -import lila.user.{ Me, User, UserPerfsRepo, UserRepo } final class StreamerPager( coll: Coll, - userRepo: UserRepo, - perfsRepo: UserPerfsRepo, + userRepo: lila.core.user.UserRepo, maxPerPage: MaxPerPage, subsRepo: lila.core.relation.SubscriptionRepo )(using Executor): @@ -20,7 +18,7 @@ final class StreamerPager( page: Int, live: LiveStreams, requests: Boolean - )(using Option[Me.Id]): Fu[Paginator[Streamer.WithContext]] = Paginator( + )(using Option[MyId]): Fu[Paginator[Streamer.WithContext]] = Paginator( currentPage = page, maxPerPage = maxPerPage, adapter = if requests then approval else notLive(live) @@ -32,7 +30,7 @@ final class StreamerPager( "_id" ) - private def notLive(live: LiveStreams)(using me: Option[Me.Id]): AdapterLike[Streamer.WithContext] = new: + private def notLive(live: LiveStreams)(using me: Option[MyId]): AdapterLike[Streamer.WithContext] = new: def nbResults: Fu[Int] = fuccess(1000) @@ -54,7 +52,7 @@ final class StreamerPager( UnwindField("user") ) .map: docs => - import lila.user.BSONHandlers.userHandler + import userRepo.userHandler for doc <- docs streamer <- doc.asOpt[Streamer] @@ -84,7 +82,7 @@ final class StreamerPager( UnwindField("user") ) .map: docs => - import lila.user.BSONHandlers.userHandler + import userRepo.userHandler for doc <- docs streamer <- doc.asOpt[Streamer] diff --git a/modules/user/src/main/UserApi.scala b/modules/user/src/main/UserApi.scala index 87b0d72459d24..5599a21b8f881 100644 --- a/modules/user/src/main/UserApi.scala +++ b/modules/user/src/main/UserApi.scala @@ -23,6 +23,7 @@ final class UserApi(userRepo: UserRepo, perfsRepo: UserPerfsRepo, cacheApi: Cach export userRepo.{ byId, + byIds, email, emailOrPrevious, pair, diff --git a/modules/user/src/main/UserRepo.scala b/modules/user/src/main/UserRepo.scala index a84259f88fd6f..6d324376d5488 100644 --- a/modules/user/src/main/UserRepo.scala +++ b/modules/user/src/main/UserRepo.scala @@ -20,6 +20,7 @@ final class UserRepo(c: Coll)(using Executor) extends lila.core.user.UserRepo(c) import lila.user.{ BSONFields as F } import lila.user.BSONHandlers.given + export lila.user.BSONHandlers.userHandler def withColl[A](f: Coll => A): A = f(coll) @@ -34,12 +35,9 @@ final class UserRepo(c: Coll)(using Executor) extends lila.core.user.UserRepo(c) case _: reactivemongo.api.bson.exceptions.BSONValueNotFoundException => none // probably GDPRed user - def byIds[U: UserIdOf]( - us: Iterable[U], - readPref: ReadPref = _.pri - ): Fu[List[User]] = + def byIds[U: UserIdOf](us: Iterable[U]): Fu[List[User]] = val ids = us.map(_.id).filter(_.noGhost) - ids.nonEmpty.so(coll.byIds[User, UserId](ids, readPref)) + ids.nonEmpty.so(coll.byIds[User, UserId](ids)) def byIdsSecondary(ids: Iterable[UserId]): Fu[List[User]] = coll.byIds[User, UserId](ids, _.sec) diff --git a/modules/user/src/main/model.scala b/modules/user/src/main/model.scala index ef596b5722a1e..9c86065d2ccbb 100644 --- a/modules/user/src/main/model.scala +++ b/modules/user/src/main/model.scala @@ -34,5 +34,5 @@ object Me extends TotalWrapper[Me, User]: given Conversion[Me, MyId] = _.id.into(MyId) given (using me: Me): MyId = Me.myId(me) given (using me: MyId): Option[MyId] = Some(me) -extension (me: Me.Id) inline def modId: ModId = me.into(ModId) +extension (me: MyId) inline def modId: ModId = me.into(ModId) given (using me: Me): LightUser.Me = LightUser.Me(me.light)