inject light user API into notify JSON handlers
parent
33ebe4a10e
commit
fc94564718
|
@ -8,10 +8,10 @@ import views.html
|
|||
|
||||
object Notify extends LilaController {
|
||||
|
||||
import lila.notify.JSONHandlers._
|
||||
|
||||
val env = Env.notifyModule
|
||||
|
||||
import env.jsonHandlers._
|
||||
|
||||
val appMaxNotifications = 10
|
||||
|
||||
def recent = Auth { implicit ctx =>
|
||||
|
|
|
@ -3,7 +3,11 @@ package lila.notify
|
|||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
|
||||
final class Env(db: lila.db.Env, config: Config, system: ActorSystem) {
|
||||
final class Env(
|
||||
db: lila.db.Env,
|
||||
config: Config,
|
||||
getLightUser: lila.common.LightUser.Getter,
|
||||
system: ActorSystem) {
|
||||
|
||||
val settings = new {
|
||||
val collectionNotifications = config getString "collection.notify"
|
||||
|
@ -12,15 +16,21 @@ final class Env(db: lila.db.Env, config: Config, system: ActorSystem) {
|
|||
|
||||
import settings._
|
||||
|
||||
val jsonHandlers = new JSONHandlers(getLightUser)
|
||||
|
||||
private lazy val repo = new NotificationRepo(coll = db(collectionNotifications))
|
||||
|
||||
lazy val notifyApi = new NotifyApi(bus = system.lilaBus, repo = repo)
|
||||
lazy val notifyApi = new NotifyApi(
|
||||
bus = system.lilaBus,
|
||||
jsonHandlers = jsonHandlers,
|
||||
repo = repo)
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
||||
lazy val current = "notify" boot new Env(db = lila.db.Env.current,
|
||||
config = lila.common.PlayApp loadConfig "notify",
|
||||
getLightUser = lila.user.Env.current.lightUser,
|
||||
system = lila.common.PlayApp.system)
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package lila.notify
|
||||
|
||||
import play.api.libs.json.{JsValue, Json, Writes}
|
||||
import lila.common.LightUser
|
||||
import lila.user.User
|
||||
import play.api.libs.json.{ JsValue, Json, Writes }
|
||||
|
||||
|
||||
object JSONHandlers {
|
||||
final class JSONHandlers(
|
||||
getLightUser: LightUser.Getter) {
|
||||
|
||||
implicit val notificationWrites: Writes[Notification] = new Writes[Notification] {
|
||||
def writeBody(notificationContent: NotificationContent) = {
|
||||
|
@ -44,4 +44,3 @@ object JSONHandlers {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ private final class NotificationRepo(val coll: Coll) {
|
|||
"read" -> false,
|
||||
"content.type" -> "invitedStudy",
|
||||
"content.studyId" -> studyId,
|
||||
"created" -> $doc("$gt" ->DateTime.now.minusDays(7))
|
||||
"created" -> $doc("$gt" -> DateTime.now.minusDays(3))
|
||||
)
|
||||
|
||||
coll.exists(query)
|
||||
|
@ -37,7 +37,7 @@ private final class NotificationRepo(val coll: Coll) {
|
|||
"read" -> false,
|
||||
"content.type" -> "mention",
|
||||
"content.topicId" -> topicId,
|
||||
"created" -> $doc("$gt" ->DateTime.now.minusDays(7))
|
||||
"created" -> $doc("$gt" -> DateTime.now.minusDays(3))
|
||||
)
|
||||
|
||||
coll.exists(query)
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
package lila.notify
|
||||
|
||||
import scala.concurrent.Future
|
||||
import lila.common.paginator.Paginator
|
||||
import lila.db.dsl._
|
||||
import lila.db.paginator.Adapter
|
||||
import lila.hub.actorApi.SendTo
|
||||
import lila.memo.AsyncCache
|
||||
import scala.concurrent.Future
|
||||
|
||||
final class NotifyApi(bus: lila.common.Bus, repo: NotificationRepo) {
|
||||
final class NotifyApi(
|
||||
bus: lila.common.Bus,
|
||||
jsonHandlers: JSONHandlers,
|
||||
repo: NotificationRepo) {
|
||||
|
||||
import BSONHandlers.NotificationBSONHandler
|
||||
import JSONHandlers._
|
||||
import jsonHandlers._
|
||||
|
||||
def getNotifications(userId: Notification.Notifies, page: Int, perPage: Int): Fu[Paginator[Notification]] = Paginator(
|
||||
adapter = new Adapter(
|
||||
|
|
Loading…
Reference in New Issue