Skip to content

Commit

Permalink
remove streamer dep to user
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Apr 12, 2024
1 parent bb26317 commit 85dc7b4
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 77 deletions.
2 changes: 1 addition & 1 deletion 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),
Seq(coreI18n, memo),
reactivemongo.bundle
)

Expand Down
2 changes: 1 addition & 1 deletion modules/chat/src/main/ChatApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ||
Expand Down
5 changes: 4 additions & 1 deletion modules/core/src/main/user.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)]]
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion modules/irwin/src/main/IrwinApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion modules/lobby/src/main/LobbySocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/mod/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
20 changes: 10 additions & 10 deletions modules/mod/src/main/ModApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions modules/mod/src/main/Modlog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
58 changes: 29 additions & 29 deletions modules/mod/src/main/ModlogApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion modules/report/src/main/ModReportFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions modules/report/src/main/ReportApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion modules/round/src/main/Messenger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
5 changes: 2 additions & 3 deletions modules/streamer/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/streamer/src/main/LiveStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 85dc7b4

Please sign in to comment.