notify reporters, valve-style
This commit is contained in:
parent
53ca4a4c0f
commit
22dbcae995
|
@ -16,6 +16,7 @@ final class Env(
|
|||
lightUserApi: lila.user.LightUserApi,
|
||||
userSpy: String => Fu[UserSpy],
|
||||
securityApi: lila.security.Api,
|
||||
notifyApi: lila.notify.NotifyApi,
|
||||
emailAddress: lila.security.EmailAddress) {
|
||||
|
||||
private object settings {
|
||||
|
@ -39,6 +40,7 @@ final class Env(
|
|||
firewall = firewall,
|
||||
reporter = hub.actor.report,
|
||||
lightUserApi = lightUserApi,
|
||||
notifyReporters = new NotifyReporters(notifyApi, reportColl),
|
||||
lilaBus = system.lilaBus)
|
||||
|
||||
private lazy val boosting = new BoostingApi(
|
||||
|
@ -92,5 +94,6 @@ object Env {
|
|||
userSpy = lila.security.Env.current.userSpy,
|
||||
lightUserApi = lila.user.Env.current.lightUserApi,
|
||||
securityApi = lila.security.Env.current.api,
|
||||
notifyApi = lila.notify.Env.current.api,
|
||||
emailAddress = lila.security.Env.current.emailAddress)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ final class ModApi(
|
|||
userSpy: String => Fu[UserSpy],
|
||||
firewall: Firewall,
|
||||
reporter: akka.actor.ActorSelection,
|
||||
notifyReporters: NotifyReporters,
|
||||
lightUserApi: LightUserApi,
|
||||
lilaBus: lila.common.Bus) {
|
||||
|
||||
|
@ -21,7 +22,10 @@ final class ModApi(
|
|||
(user.engine != v) ?? {
|
||||
logApi.engine(mod, user.id, v) zip
|
||||
UserRepo.setEngine(user.id, v) >>- {
|
||||
if (v) lilaBus.publish(lila.hub.actorApi.mod.MarkCheater(user.id), 'adjustCheater)
|
||||
if (v) {
|
||||
lilaBus.publish(lila.hub.actorApi.mod.MarkCheater(user.id), 'adjustCheater)
|
||||
notifyReporters(user)
|
||||
}
|
||||
reporter ! lila.hub.actorApi.report.MarkCheater(user.id, mod)
|
||||
} void
|
||||
}
|
||||
|
@ -42,7 +46,10 @@ final class ModApi(
|
|||
(user.booster != v) ?? {
|
||||
logApi.booster(mod, user.id, v) zip
|
||||
UserRepo.setBooster(user.id, v) >>- {
|
||||
if (v) lilaBus.publish(lila.hub.actorApi.mod.MarkBooster(user.id), 'adjustBooster)
|
||||
if (v) {
|
||||
lilaBus.publish(lila.hub.actorApi.mod.MarkBooster(user.id), 'adjustBooster)
|
||||
notifyReporters(user)
|
||||
}
|
||||
} void
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +66,10 @@ final class ModApi(
|
|||
changed ?? {
|
||||
UserRepo.updateTroll(user).void >>-
|
||||
logApi.troll(mod, user.id, user.troll)
|
||||
} >>-
|
||||
} >>- {
|
||||
if (value) notifyReporters(user)
|
||||
(reporter ! lila.hub.actorApi.report.MarkTroll(user.id, mod)) inject user.troll
|
||||
}
|
||||
}
|
||||
|
||||
def ban(mod: String, username: String): Funit = withUser(username) { user =>
|
||||
|
|
24
modules/mod/src/main/NotifyReporters.scala
Normal file
24
modules/mod/src/main/NotifyReporters.scala
Normal file
|
@ -0,0 +1,24 @@
|
|||
package lila.mod
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.notify.{ Notification, NotifyApi }
|
||||
|
||||
private final class NotifyReporters(
|
||||
notifyApi: NotifyApi,
|
||||
reportColl: Coll) {
|
||||
|
||||
def apply(user: lila.user.User): Funit =
|
||||
reportColl.distinct("createdBy", $doc(
|
||||
"user" -> user.id,
|
||||
"createdAt" -> $gt(DateTime.now minusDays 3),
|
||||
"createdBy" -> $ne("lichess")
|
||||
).some) map lila.db.BSON.asStrings flatMap {
|
||||
_.map { reporterId =>
|
||||
notifyApi.addNotification(Notification(
|
||||
notifies = Notification.Notifies(reporterId),
|
||||
content = lila.notify.ReportedBanned).pp)
|
||||
}.sequenceFu.void
|
||||
}
|
||||
}
|
|
@ -75,6 +75,7 @@ private object BSONHandlers {
|
|||
case x: GameEnd => GameEndHandler.write(x)
|
||||
case x: PlanStart => PlanStartHandler.write(x)
|
||||
case x: PlanExpire => PlanExpireHandler.write(x)
|
||||
case ReportedBanned => $empty
|
||||
}
|
||||
} ++ $doc("type" -> notificationContent.key)
|
||||
|
||||
|
@ -107,6 +108,7 @@ private object BSONHandlers {
|
|||
case "gameEnd" => GameEndHandler read reader.doc
|
||||
case "planStart" => PlanStartHandler read reader.doc
|
||||
case "planExpire" => PlanExpireHandler read reader.doc
|
||||
case "reportedBanned" => ReportedBanned
|
||||
}
|
||||
|
||||
def writes(writer: Writer, n: NotificationContent): dsl.Bdoc = writeNotificationContent(n)
|
||||
|
|
|
@ -36,7 +36,7 @@ final class JSONHandlers(
|
|||
"id" -> id.value,
|
||||
"slug" -> slug.value,
|
||||
"title" -> title.value)
|
||||
case LimitedTournamentInvitation => Json.obj()
|
||||
case LimitedTournamentInvitation | ReportedBanned => Json.obj()
|
||||
case GameEnd(gameId, opponentId, win) => Json.obj(
|
||||
"id" -> gameId.value,
|
||||
"opponent" -> opponentId.map(_.value).flatMap(getLightUser),
|
||||
|
|
|
@ -114,5 +114,7 @@ object GameEnd {
|
|||
case class Win(value: Boolean) extends AnyVal
|
||||
}
|
||||
|
||||
case object ReportedBanned extends NotificationContent("reportedBanned")
|
||||
|
||||
case class PlanStart(userId: String) extends NotificationContent("planStart")
|
||||
case class PlanExpire(userId: String) extends NotificationContent("planExpire")
|
||||
|
|
|
@ -152,7 +152,7 @@ object ApplicationBuild extends Build {
|
|||
play.api, play.test, RM)
|
||||
)
|
||||
|
||||
lazy val mod = project("mod", Seq(common, db, user, hub, security, game, analyse, evaluation, report)).settings(
|
||||
lazy val mod = project("mod", Seq(common, db, user, hub, security, game, analyse, evaluation, report, notifyModule)).settings(
|
||||
libraryDependencies ++= provided(
|
||||
play.api, play.test, RM)
|
||||
)
|
||||
|
|
|
@ -146,6 +146,19 @@ var handlers = {
|
|||
return 'Game with ' + n.content.opponentName + '.';
|
||||
}
|
||||
},
|
||||
reportedBanned: {
|
||||
html: function(notification) {
|
||||
return genericNotification(notification, '', '', [
|
||||
m('span', [
|
||||
m('strong', 'Someone you reported was banned')
|
||||
]),
|
||||
m('span', 'Thank you for helping lichess community.')
|
||||
]);
|
||||
},
|
||||
text: function(n) {
|
||||
return 'Someone you reported was banned';
|
||||
}
|
||||
},
|
||||
gameEnd: {
|
||||
html: function(notification) {
|
||||
var content = notification.content
|
||||
|
|
Loading…
Reference in a new issue