new coach review notification

This commit is contained in:
Thibault Duplessis 2016-09-01 13:12:23 +02:00
parent 584493c6b8
commit 215f3ac9f8
7 changed files with 32 additions and 5 deletions

View file

@ -5,13 +5,15 @@ import scala.concurrent.duration._
import lila.db.dsl._
import lila.memo.AsyncCache
import lila.notify.{ Notification, NotifyApi }
import lila.security.Granter
import lila.user.{ User, UserRepo }
final class CoachApi(
coachColl: Coll,
reviewColl: Coll,
photographer: Photographer) {
photographer: Photographer,
notifyApi: NotifyApi) {
import BsonHandlers._
@ -95,7 +97,11 @@ final class CoachApi(
approved = false,
updatedAt = DateTime.now)
}
reviewColl.update($id(id), review, upsert = true) inject review
reviewColl.update($id(id), review, upsert = true) >>
notifyApi.addNotification(Notification(
notifies = Notification.Notifies(coach.id.value),
content = lila.notify.CoachReview
)) inject review
}
def byId(id: String) = reviewColl.byId[CoachReview](id)

View file

@ -8,6 +8,7 @@ import lila.common.PimpedConfig._
final class Env(
config: Config,
notifyApi: lila.notify.NotifyApi,
db: lila.db.Env) {
private val CollectionCoach = config getString "collection.coach"
@ -23,7 +24,8 @@ final class Env(
lazy val api = new CoachApi(
coachColl = coachColl,
reviewColl = reviewColl,
photographer = photographer)
photographer = photographer,
notifyApi = notifyApi)
def cli = new lila.common.Cli {
def process = {
@ -37,5 +39,6 @@ object Env {
lazy val current: Env = "coach" boot new Env(
config = lila.common.PlayApp loadConfig "coach",
notifyApi = lila.notify.Env.current.api,
db = lila.db.Env.current)
}

View file

@ -79,6 +79,7 @@ private object BSONHandlers {
case x: PlanExpire => PlanExpireHandler.write(x)
case x: RatingRefund => RatingRefundHandler.write(x)
case ReportedBanned => $empty
case CoachReview => $empty
}
} ++ $doc("type" -> notificationContent.key)
@ -113,6 +114,7 @@ private object BSONHandlers {
case "planExpire" => PlanExpireHandler read reader.doc
case "ratingRefund" => RatingRefundHandler read reader.doc
case "reportedBanned" => ReportedBanned
case "coachReview" => CoachReview
}
def writes(writer: Writer, n: NotificationContent): dsl.Bdoc = writeNotificationContent(n)

View file

@ -36,7 +36,7 @@ final class JSONHandlers(
"id" -> id.value,
"slug" -> slug.value,
"title" -> title.value)
case LimitedTournamentInvitation | ReportedBanned => Json.obj()
case LimitedTournamentInvitation | ReportedBanned | CoachReview => Json.obj()
case GameEnd(gameId, opponentId, win) => Json.obj(
"id" -> gameId.value,
"opponent" -> opponentId.map(_.value).flatMap(getLightUser),

View file

@ -118,5 +118,7 @@ case object ReportedBanned extends NotificationContent("reportedBanned")
case class RatingRefund(perf: String, points: Int) extends NotificationContent("ratingRefund")
case object CoachReview extends NotificationContent("coachReview")
case class PlanStart(userId: String) extends NotificationContent("planStart")
case class PlanExpire(userId: String) extends NotificationContent("planExpire")

View file

@ -90,7 +90,7 @@ object ApplicationBuild extends Build {
)
lazy val coach = project("coach", Seq(
common, hub, db, user, security)).settings(
common, hub, db, user, security, notifyModule)).settings(
libraryDependencies ++= provided(play.api, RM, scrimage)
)

View file

@ -226,6 +226,20 @@ var handlers = {
return 'Patron account expired';
}
},
coachReview: {
html: function(notification) {
return genericNotification(notification, '/coach/edit', ':', [
m('span', [
m('strong', 'New pending review'),
drawTime(notification)
]),
m('span', 'Someone reviewed your coach profile.')
]);
},
text: function(n) {
return 'New pending review';
}
},
ratingRefund: {
html: function(notification) {
var content = notification.content