Skip to content

Commit

Permalink
add appeal messages to moderator log
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 21, 2024
1 parent fce0585 commit cbd81fe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/controllers/Mod.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import lila.core.net.IpAddress
import lila.core.perm.Permission
import lila.core.security.FingerHash
import lila.core.userId.ModId
import lila.mod.ModUserSearch
import lila.mod.{ Modlog, ModUserSearch }
import lila.report.{ Mod as AsMod, Suspect }

final class Mod(
Expand Down Expand Up @@ -226,7 +226,13 @@ final class Mod(

def log = Secure(_.GamifyView) { ctx ?=> me ?=>
Ok.async:
env.mod.logApi.recentBy(me).map(views.mod.ui.myLogs(_))
for
log <- env.mod.logApi.recentBy(me)
appeals <- env.appeal.api.myLog(log.lastOption.map(_.date).|(nowInstant.minusMonths(1)))
appealsLog = appeals.map: (user, msg) =>
Modlog(user.some, "appeal", msg.text.some).copy(date = msg.at)
sorted = (log ::: appealsLog).sortBy(_.date).reverse
yield views.mod.ui.myLogs(sorted)
}

private def communications(username: UserStr, priv: Boolean) =
Expand Down
18 changes: 18 additions & 0 deletions modules/appeal/src/main/AppealApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ final class AppealApi(

def countUnread = coll.countSel($doc("status" -> Appeal.Status.Unread.key))

def myLog(since: Instant)(using me: Me): Fu[List[(UserId, AppealMsg)]] =
coll
.aggregateList(maxDocs = 50, _.sec): framework =>
import framework.*
Match($doc("msgs.by" -> me.userId)) -> List(
Project($doc("msgs" -> 1)),
Unwind("msgs"),
Match($doc("msgs.by" -> me.userId, "msgs.at".$gt(since))),
Sort(Descending("msgs.at")),
Limit(50)
)
.map: docs =>
for
doc <- docs
userId <- doc.getAsOpt[UserId]("_id")
msg <- doc.getAsOpt[AppealMsg]("msgs")
yield userId -> msg

def myQueue(filter: Option[Filter])(using me: Me) =
bothQueues(filter, snoozer.snoozedKeysOf(me.userId).map(_.appealId.userId))

Expand Down
6 changes: 3 additions & 3 deletions modules/mod/src/main/ModlogApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres
.list(100)

def userHistory(userId: UserId): Fu[List[Modlog]] =
coll.find($doc("user" -> userId)).sort($sort.desc("date")).cursor[Modlog]().list(60)
coll.secondaryPreferred.find($doc("user" -> userId)).sort($sort.desc("date")).cursor[Modlog]().list(60)

def countRecentCheatDetected(userId: UserId): Fu[Int] =
coll.secondaryPreferred.countSel:
Expand All @@ -289,11 +289,11 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres
)

def recentBy(mod: Mod) =
coll.tempPrimary
coll.secondaryPreferred
.find($doc("mod" -> mod.id))
.sort($sort.desc("date"))
.cursor[Modlog]()
.list(100)
.list(200)

def addModlog(users: List[UserWithPerfs]): Fu[List[UserWithModlog]] =
coll.tempPrimary
Expand Down
2 changes: 1 addition & 1 deletion modules/mod/src/main/ui/ModUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class ModUi(helpers: Helpers)(isChatPanic: () => Boolean):
userIdLink(u.some, params = "?mod")
}),
td(log.showAction.capitalize),
td(log.details)
td(shorten(~log.details, 100))
)
)
)
Expand Down

0 comments on commit cbd81fe

Please sign in to comment.