show mod notes in report list
This commit is contained in:
parent
e49049f53e
commit
5da0fce2ff
|
@ -1,4 +1,6 @@
|
|||
@(reports: List[lila.report.Report.WithUser])(implicit ctx: Context)
|
||||
@(reports: List[lila.report.Report.WithUserAndNotes])(implicit ctx: Context)
|
||||
|
||||
@import lila.report.Report.{WithUser,WithUserAndNotes}
|
||||
|
||||
@title = @{ "User reports" }
|
||||
|
||||
|
@ -39,7 +41,7 @@ moreJs = moreJs) {
|
|||
</thead>
|
||||
<tbody>
|
||||
@reports.map {
|
||||
case lila.report.Report.WithUser(r, u, _) if (!r.isTrollOrInsult || isGranted(_.MarkTroll)) => {
|
||||
case WithUserAndNotes(WithUser(r, u, _), notes) if (!r.isTrollOrInsult || isGranted(_.MarkTroll)) => {
|
||||
<tr class="@r.unprocessed.fold("new", "")">
|
||||
<td>@userIdLink(r.createdBy.some)<br />@momentFormat(r.createdAt)</td>
|
||||
<td>@userLink(u, params = "?mod")<br />@showBestPerf(u)</td>
|
||||
|
@ -49,6 +51,12 @@ moreJs = moreJs) {
|
|||
@if(r.unprocessed && r.isCommunication) {
|
||||
<a data-icon="v" style="display:inline-block" class="button" href="@routes.Mod.communication(r.user)"> View the communication report</a>
|
||||
}
|
||||
@if(notes.nonEmpty) {
|
||||
<br />
|
||||
<a href="@routes.User.show(u.username)?notes=1">
|
||||
<strong>@pluralize("note", notes.size) by @notes.map(_.from).map(usernameOrId).mkString(", ")</strong>
|
||||
</a>
|
||||
}
|
||||
</td>
|
||||
<td>@r.processedBy.map { u =>
|
||||
}.getOrElse {
|
||||
|
|
|
@ -9,6 +9,7 @@ final class Env(
|
|||
config: Config,
|
||||
db: lila.db.Env,
|
||||
isOnline: lila.user.User.ID => Boolean,
|
||||
noteApi: lila.user.NoteApi,
|
||||
system: ActorSystem,
|
||||
hub: lila.hub.Env) {
|
||||
|
||||
|
@ -17,7 +18,7 @@ final class Env(
|
|||
|
||||
lazy val forms = new DataForm(hub.actor.captcher)
|
||||
|
||||
lazy val api = new ReportApi(reportColl, isOnline)
|
||||
lazy val api = new ReportApi(reportColl, noteApi, isOnline)
|
||||
|
||||
// api actor
|
||||
system.actorOf(Props(new Actor {
|
||||
|
@ -48,6 +49,7 @@ object Env {
|
|||
config = lila.common.PlayApp loadConfig "report",
|
||||
db = lila.db.Env.current,
|
||||
isOnline = lila.user.Env.current.isOnline,
|
||||
noteApi = lila.user.Env.current.noteApi,
|
||||
system = lila.common.PlayApp.system,
|
||||
hub = lila.hub.Env.current)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package lila.report
|
|||
import org.joda.time.DateTime
|
||||
import ornicar.scalalib.Random
|
||||
|
||||
import lila.user.User
|
||||
import lila.user.{ User, Note }
|
||||
|
||||
case class Report(
|
||||
_id: String, // also the url slug
|
||||
|
@ -50,6 +50,11 @@ object Report {
|
|||
(report.processed ?? Int.MinValue)
|
||||
}
|
||||
|
||||
case class WithUserAndNotes(withUser: WithUser, notes: List[Note]) {
|
||||
def report = withUser.report
|
||||
def user = withUser.user
|
||||
}
|
||||
|
||||
def make(
|
||||
user: User,
|
||||
reason: Reason,
|
||||
|
|
|
@ -4,10 +4,11 @@ import akka.actor.ActorSelection
|
|||
import org.joda.time.DateTime
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.user.{ User, UserRepo }
|
||||
import lila.user.{ User, UserRepo, NoteApi }
|
||||
|
||||
private[report] final class ReportApi(
|
||||
coll: Coll,
|
||||
noteApi: NoteApi,
|
||||
isOnline: User.ID => Boolean) {
|
||||
|
||||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
|
@ -155,7 +156,7 @@ private[report] final class ReportApi(
|
|||
def recent(nb: Int) =
|
||||
coll.find($empty).sort($sort.createdDesc).cursor[Report]().gather[List](nb)
|
||||
|
||||
def unprocessedAndRecent(nb: Int): Fu[List[Report.WithUser]] =
|
||||
def unprocessedAndRecent(nb: Int): Fu[List[Report.WithUserAndNotes]] =
|
||||
recentUnprocessed(nb * 2) |+| recentProcessed(nb) flatMap { all =>
|
||||
val reports = all take nb
|
||||
UserRepo byIds reports.map(_.user).distinct map { users =>
|
||||
|
@ -167,6 +168,12 @@ private[report] final class ReportApi(
|
|||
}
|
||||
} map {
|
||||
_.sortBy(-_.urgency).take(nb * 2)
|
||||
} flatMap { withUsers =>
|
||||
noteApi.byUserIdsForMod(withUsers.map(_.user.id).distinct) map { notes =>
|
||||
withUsers.map { wu =>
|
||||
Report.WithUserAndNotes(wu, notes.filter(_.to == wu.user.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def recentUnprocessed(nb: Int) =
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.user
|
|||
|
||||
import lila.db.dsl._
|
||||
import org.joda.time.DateTime
|
||||
import reactivemongo.api.ReadPreference
|
||||
|
||||
case class Note(
|
||||
_id: String,
|
||||
|
@ -26,9 +27,17 @@ final class NoteApi(
|
|||
"to" -> user.id,
|
||||
"from" $in (myFriendIds + me.id)) ++
|
||||
me.troll.fold($empty, $doc("troll" -> false)) ++
|
||||
isMod.fold($empty, $doc("mod" $ne true))
|
||||
isMod.fold($empty, $doc("mod" -> false))
|
||||
).sort($doc("date" -> -1)).cursor[Note]().gather[List](20)
|
||||
|
||||
def byUserIdsForMod(ids: List[User.ID]): Fu[List[Note]] =
|
||||
coll.find($doc(
|
||||
"to" $in ids,
|
||||
"mod" -> true
|
||||
)).sort($doc("date" -> -1))
|
||||
.cursor[Note](readPreference = ReadPreference.secondaryPreferred)
|
||||
.gather[List](ids.size * 5)
|
||||
|
||||
def write(to: User, text: String, from: User, modOnly: Boolean) = {
|
||||
|
||||
val note = Note(
|
||||
|
|
Loading…
Reference in a new issue