prioritize reports which target is currently online
This commit is contained in:
parent
145c236fc1
commit
e49049f53e
|
@ -39,7 +39,7 @@ moreJs = moreJs) {
|
|||
</thead>
|
||||
<tbody>
|
||||
@reports.map {
|
||||
case lila.report.Report.WithUser(r, u) if (!r.isTrollOrInsult || isGranted(_.MarkTroll)) => {
|
||||
case lila.report.Report.WithUser(r, u, _) 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>
|
||||
|
|
|
@ -8,6 +8,7 @@ import lila.common.PimpedConfig._
|
|||
final class Env(
|
||||
config: Config,
|
||||
db: lila.db.Env,
|
||||
isOnline: lila.user.User.ID => Boolean,
|
||||
system: ActorSystem,
|
||||
hub: lila.hub.Env) {
|
||||
|
||||
|
@ -16,7 +17,7 @@ final class Env(
|
|||
|
||||
lazy val forms = new DataForm(hub.actor.captcher)
|
||||
|
||||
lazy val api = new ReportApi(reportColl)
|
||||
lazy val api = new ReportApi(reportColl, isOnline)
|
||||
|
||||
// api actor
|
||||
system.actorOf(Props(new Actor {
|
||||
|
@ -46,6 +47,7 @@ object Env {
|
|||
lazy val current = "report" boot new Env(
|
||||
config = lila.common.PlayApp loadConfig "report",
|
||||
db = lila.db.Env.current,
|
||||
isOnline = lila.user.Env.current.isOnline,
|
||||
system = lila.common.PlayApp.system,
|
||||
hub = lila.hub.Env.current)
|
||||
}
|
||||
|
|
|
@ -35,13 +35,20 @@ case class Report(
|
|||
def process(by: User) = copy(processedBy = by.id.some)
|
||||
|
||||
def unprocessed = processedBy.isEmpty
|
||||
def processed = processedBy.isDefined
|
||||
|
||||
lazy val realReason: Reason = Reason byName reason
|
||||
}
|
||||
|
||||
object Report {
|
||||
|
||||
case class WithUser(report: Report, user: User)
|
||||
case class WithUser(report: Report, user: User, isOnline: Boolean) {
|
||||
|
||||
def urgency: Int =
|
||||
(nowSeconds - report.createdAt.getSeconds).toInt +
|
||||
(isOnline ?? (86400 * 5)) +
|
||||
(report.processed ?? Int.MinValue)
|
||||
}
|
||||
|
||||
def make(
|
||||
user: User,
|
||||
|
|
|
@ -6,7 +6,9 @@ import org.joda.time.DateTime
|
|||
import lila.db.dsl._
|
||||
import lila.user.{ User, UserRepo }
|
||||
|
||||
private[report] final class ReportApi(coll: Coll) {
|
||||
private[report] final class ReportApi(
|
||||
coll: Coll,
|
||||
isOnline: User.ID => Boolean) {
|
||||
|
||||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
private implicit val ReportBSONHandler = reactivemongo.bson.Macros.handler[Report]
|
||||
|
@ -154,13 +156,17 @@ private[report] final class ReportApi(coll: Coll) {
|
|||
coll.find($empty).sort($sort.createdDesc).cursor[Report]().gather[List](nb)
|
||||
|
||||
def unprocessedAndRecent(nb: Int): Fu[List[Report.WithUser]] =
|
||||
recentUnprocessed(nb) |+| recentProcessed(nb) flatMap { all =>
|
||||
recentUnprocessed(nb * 2) |+| recentProcessed(nb) flatMap { all =>
|
||||
val reports = all take nb
|
||||
UserRepo byIds reports.map(_.user).distinct map { users =>
|
||||
reports.flatMap { r =>
|
||||
users.find(_.id == r.user) map { Report.WithUser(r, _) }
|
||||
users.find(_.id == r.user) map { u =>
|
||||
Report.WithUser(r, u, isOnline(u.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
} map {
|
||||
_.sortBy(-_.urgency).take(nb * 2)
|
||||
}
|
||||
|
||||
def recentUnprocessed(nb: Int) =
|
||||
|
|
|
@ -41,11 +41,11 @@ final class Env(
|
|||
|
||||
val forms = DataForm
|
||||
|
||||
def lightUser(id: String): Option[lila.common.LightUser] = lightUserApi get id
|
||||
def lightUser(id: User.ID): Option[lila.common.LightUser] = lightUserApi get id
|
||||
|
||||
def uncacheLightUser(id: String): Funit = lightUserApi invalidate id
|
||||
def uncacheLightUser(id: User.ID): Funit = lightUserApi invalidate id
|
||||
|
||||
def isOnline(userId: String) = onlineUserIdMemo get userId
|
||||
def isOnline(userId: User.ID): Boolean = onlineUserIdMemo get userId
|
||||
|
||||
def cli = new lila.common.Cli {
|
||||
def process = {
|
||||
|
|
Loading…
Reference in a new issue