2016-05-30 06:51:36 -06:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import lila.app._
|
|
|
|
import lila.notify.Notification.Notifies
|
|
|
|
|
|
|
|
import play.api.libs.json._
|
|
|
|
import views.html
|
|
|
|
|
2016-05-31 06:43:09 -06:00
|
|
|
object Notify extends LilaController {
|
2016-05-30 06:51:36 -06:00
|
|
|
|
|
|
|
import lila.notify.JSONHandlers._
|
|
|
|
|
2016-05-31 07:19:12 -06:00
|
|
|
val env = Env.notifyModule
|
2016-05-30 06:51:36 -06:00
|
|
|
|
2016-05-31 06:53:47 -06:00
|
|
|
val appMaxNotifications = 10
|
|
|
|
|
2016-05-30 06:51:36 -06:00
|
|
|
def recent = Auth { implicit ctx =>
|
|
|
|
me =>
|
|
|
|
val notifies = Notifies(me.id)
|
2016-05-31 06:53:47 -06:00
|
|
|
env.notifyApi.getNotifications(notifies, 1, appMaxNotifications) map {
|
2016-05-30 06:51:36 -06:00
|
|
|
notifications => Ok(Json.toJson(notifications.currentPageResults)) as JSON
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def markAllAsRead = Auth {
|
|
|
|
implicit ctx =>
|
|
|
|
me =>
|
|
|
|
val userId = Notifies(me.id)
|
2016-05-31 06:53:47 -06:00
|
|
|
env.notifyApi.getNotifications(userId, 1, appMaxNotifications) flatMap { notifications =>
|
|
|
|
notifications.currentPageResults.exists(_.unread).?? {
|
|
|
|
env.notifyApi.markAllRead(userId)
|
|
|
|
} inject {
|
|
|
|
Ok(Json.toJson(notifications.currentPageResults)) as JSON
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 06:51:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def notificationsPage = Auth { implicit ctx =>
|
|
|
|
me =>
|
|
|
|
val notifies = Notifies(me.id)
|
|
|
|
env.notifyApi.getNotifications(notifies, 1, perPage = 100) map {
|
2016-05-31 06:43:09 -06:00
|
|
|
notifications => Ok(html.notify.view(notifications.currentPageResults.toList))
|
2016-05-30 06:51:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|