lila/modules/chat/src/main/Env.scala

60 lines
1.7 KiB
Scala
Raw Normal View History

2013-12-26 12:30:57 -07:00
package lila.chat
2015-04-29 09:04:55 -06:00
import akka.actor.{ ActorSystem, Props, ActorSelection }
2013-12-26 12:30:57 -07:00
import com.typesafe.config.Config
2016-06-10 12:20:56 -06:00
import scala.concurrent.duration._
2013-12-26 12:30:57 -07:00
import lila.common.PimpedConfig._
final class Env(
config: Config,
db: lila.db.Env,
2014-01-31 15:54:34 -07:00
flood: lila.security.Flood,
2015-04-29 09:04:55 -06:00
shutup: ActorSelection,
2014-01-31 15:54:34 -07:00
system: ActorSystem) {
2013-12-26 12:30:57 -07:00
private val settings = new {
2014-01-28 07:45:28 -07:00
val CollectionChat = config getString "collection.chat"
2016-06-10 09:15:00 -06:00
val CollectionTimeout = config getString "collection.timeout"
2014-01-28 17:42:38 -07:00
val MaxLinesPerChat = config getInt "max_lines"
2013-12-26 12:30:57 -07:00
val NetDomain = config getString "net.domain"
2014-02-01 01:21:18 -07:00
val ActorName = config getString "actor.name"
2016-06-10 12:20:56 -06:00
val TimeoutDuration = config duration "timeout.duration"
val TimeoutCheckEvery = config duration "timeout.check_every"
2013-12-26 12:30:57 -07:00
}
import settings._
2016-06-10 12:20:56 -06:00
private val chatTimeout = new ChatTimeout(
chatColl = chatColl,
timeoutColl = timeoutColl,
duration = TimeoutDuration)
2016-06-09 15:42:54 -06:00
val api = new ChatApi(
2014-01-28 17:42:38 -07:00
coll = chatColl,
2016-06-10 12:20:56 -06:00
chatTimeout = chatTimeout,
2014-01-28 17:42:38 -07:00
flood = flood,
2015-04-25 10:55:54 -06:00
shutup = shutup,
2016-06-10 12:20:56 -06:00
lilaBus = system.lilaBus,
2014-01-28 17:42:38 -07:00
maxLinesPerChat = MaxLinesPerChat,
netDomain = NetDomain)
2016-06-10 12:20:56 -06:00
system.scheduler.schedule(TimeoutCheckEvery, TimeoutCheckEvery) {
2016-06-10 14:38:11 -06:00
chatTimeout.checkExpired foreach api.userChat.reinstate
2016-06-10 12:20:56 -06:00
}
2016-06-09 15:42:54 -06:00
2016-06-10 12:20:56 -06:00
system.actorOf(Props(new FrontActor(api)), name = ActorName)
2014-01-31 15:54:34 -07:00
2014-01-28 07:45:28 -07:00
private[chat] lazy val chatColl = db(CollectionChat)
2016-06-10 09:15:00 -06:00
private[chat] lazy val timeoutColl = db(CollectionTimeout)
2013-12-26 12:30:57 -07:00
}
object Env {
2015-08-31 18:36:08 -06:00
lazy val current: Env = "chat" boot new Env(
2013-12-26 12:30:57 -07:00
config = lila.common.PlayApp loadConfig "chat",
db = lila.db.Env.current,
2014-01-31 15:54:34 -07:00
flood = lila.security.Env.current.flood,
2015-04-29 09:04:55 -06:00
shutup = lila.hub.Env.current.actor.shutup,
2014-01-31 15:54:34 -07:00
system = lila.common.PlayApp.system)
2013-12-26 12:30:57 -07:00
}