forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Env.scala
68 lines (57 loc) · 1.85 KB
/
Env.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package lila.relation
import akka.actor._
import akka.pattern.pipe
import com.typesafe.config.Config
import lila.common.PimpedConfig._
final class Env(
config: Config,
db: lila.db.Env,
hub: lila.hub.Env,
getOnlineUserIds: () => Set[String],
lightUser: String => Option[lila.common.LightUser],
followable: String => Fu[Boolean],
system: ActorSystem,
scheduler: lila.common.Scheduler) {
private val settings = new {
val CollectionRelation = config getString "collection.relation"
val ActorNotifyFreq = config duration "actor.notify_freq"
val ActorName = config getString "actor.name"
val MaxFollow = config getInt "limit.follow"
val MaxBlock = config getInt "limit.block"
}
import settings._
lazy val api = new RelationApi(
coll = relationColl,
actor = hub.actor.relation,
bus = system.lilaBus,
timeline = hub.actor.timeline,
reporter = hub.actor.report,
followable = followable,
maxFollow = MaxFollow,
maxBlock = MaxBlock)
private[relation] val actor = system.actorOf(Props(new RelationActor(
getOnlineUserIds = getOnlineUserIds,
lightUser = lightUser,
api = api
)), name = ActorName)
{
import scala.concurrent.duration._
scheduler.once(15 seconds) {
scheduler.message(ActorNotifyFreq) {
actor -> actorApi.NotifyMovement
}
}
}
private[relation] lazy val relationColl = db(CollectionRelation)
}
object Env {
lazy val current = "relation" boot new Env(
config = lila.common.PlayApp loadConfig "relation",
db = lila.db.Env.current,
hub = lila.hub.Env.current,
getOnlineUserIds = () => lila.user.Env.current.onlineUserIdMemo.keySet,
lightUser = lila.user.Env.current.lightUser,
followable = lila.pref.Env.current.api.followable _,
system = lila.common.PlayApp.system,
scheduler = lila.common.PlayApp.scheduler)
}