propagate user activity through akka event bus
This commit is contained in:
parent
8b9febe9f9
commit
7ce725bc52
|
@ -5,7 +5,7 @@ import com.typesafe.config.Config
|
|||
|
||||
final class Env(
|
||||
config: Config,
|
||||
system: ActorSystem,
|
||||
val system: ActorSystem,
|
||||
appPath: String) {
|
||||
|
||||
val CliUsername = config getString "cli.username"
|
||||
|
|
|
@ -172,10 +172,8 @@ private[controllers] trait LilaController
|
|||
private def restoreUser(req: RequestHeader): Fu[Option[UserModel]] =
|
||||
Env.security.api restoreUser req addEffect {
|
||||
_ foreach { user ⇒
|
||||
if (!user.seenRecently) UserRepo setSeenAt user.id
|
||||
val lang = Env.i18n.pool.lang(req).language
|
||||
if (user.lang != lang.some) UserRepo.setLang(user.id, lang)
|
||||
Env.user setOnline user
|
||||
Env.current.system.eventStream publish lila.user.User.Active(user, lang)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package lila.user
|
||||
|
||||
import akka.actor._
|
||||
import chess.EloCalculator
|
||||
import com.typesafe.config.Config
|
||||
|
||||
|
@ -10,7 +11,7 @@ final class Env(
|
|||
config: Config,
|
||||
db: lila.db.Env,
|
||||
scheduler: lila.common.Scheduler,
|
||||
system: akka.actor.ActorSystem) {
|
||||
system: ActorSystem) {
|
||||
|
||||
private val settings = new {
|
||||
val PaginatorMaxPerPage = config getInt "paginator.max_per_page"
|
||||
|
@ -46,8 +47,6 @@ final class Env(
|
|||
|
||||
def usernameOrAnonymous(id: String): Fu[String] = cached usernameOrAnonymous id
|
||||
|
||||
def setOnline(user: User) { onlineUserIdMemo put user.id }
|
||||
|
||||
def isOnline(userId: String) = onlineUserIdMemo get userId
|
||||
|
||||
def countEnabled = cached.countEnabled
|
||||
|
@ -61,6 +60,18 @@ final class Env(
|
|||
}
|
||||
}
|
||||
|
||||
system.actorOf(
|
||||
Props(new Actor {
|
||||
context.system.eventStream.subscribe(self, classOf[User.Active])
|
||||
def receive = {
|
||||
case User.Active(user, lang) ⇒ {
|
||||
if (!user.seenRecently) UserRepo setSeenAt user.id
|
||||
if (user.lang != lang.some) UserRepo.setLang(user.id, lang)
|
||||
onlineUserIdMemo put user.id
|
||||
}
|
||||
}
|
||||
}), name = "user-active")
|
||||
|
||||
{
|
||||
import scala.concurrent.duration._
|
||||
import lila.hub.actorApi.WithUserIds
|
||||
|
|
|
@ -59,6 +59,8 @@ object User {
|
|||
|
||||
val anonymous = "Anonymous"
|
||||
|
||||
case class Active(user: User, lang: String)
|
||||
|
||||
import lila.db.Tube
|
||||
import Tube.Helpers._
|
||||
import play.api.libs.json._
|
||||
|
|
Loading…
Reference in a new issue