Display ping on powertip

This commit is contained in:
Isaac Levy 2017-07-03 16:04:28 -04:00
parent c32f473d29
commit 0a3013f257
3 changed files with 20 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import play.api.libs.json._
import play.api.mvc._ import play.api.mvc._
import scala.concurrent.duration._ import scala.concurrent.duration._
import chess.Centis
import lila.api.BodyContext import lila.api.BodyContext
import lila.app._ import lila.app._
import lila.app.mashup.GameFilterMenu import lila.app.mashup.GameFilterMenu
@ -12,6 +13,7 @@ import lila.common.{ IpAddress, HTTPRequest }
import lila.game.{ GameRepo, Game => GameModel } import lila.game.{ GameRepo, Game => GameModel }
import lila.rating.PerfType import lila.rating.PerfType
import lila.user.{ User => UserModel, UserRepo } import lila.user.{ User => UserModel, UserRepo }
import lila.socket.UserLagCache
import views._ import views._
object User extends LilaController { object User extends LilaController {
@ -46,6 +48,13 @@ object User extends LilaController {
filter(username, none, 1) filter(username, none, 1)
} }
private def connQuality(lag: Centis) = lag.centis match {
case c if c < 15 => 4
case c if c < 25 => 3
case c if c < 50 => 2
case _ => 1
}
def showMini(username: String) = Open { implicit ctx => def showMini(username: String) = Open { implicit ctx =>
OptionFuResult(UserRepo named username) { user => OptionFuResult(UserRepo named username) { user =>
if (user.enabled) for { if (user.enabled) for {
@ -53,9 +62,10 @@ object User extends LilaController {
crosstable <- ctx.userId ?? { Env.game.crosstableApi(user.id, _) } crosstable <- ctx.userId ?? { Env.game.crosstableApi(user.id, _) }
followable <- ctx.isAuth ?? { Env.pref.api.followable(user.id) } followable <- ctx.isAuth ?? { Env.pref.api.followable(user.id) }
relation <- ctx.userId ?? { relationApi.fetchRelation(_, user.id) } relation <- ctx.userId ?? { relationApi.fetchRelation(_, user.id) }
ping = UserLagCache.get(user.id) map connQuality
res <- negotiate( res <- negotiate(
html = !ctx.is(user) ?? GameRepo.lastPlayedPlaying(user) map { pov => html = !ctx.is(user) ?? GameRepo.lastPlayedPlaying(user) map { pov =>
Ok(html.user.mini(user, pov, blocked, followable, relation, crosstable)) Ok(html.user.mini(user, pov, blocked, followable, relation, ping, crosstable))
.withHeaders(CACHE_CONTROL -> "max-age=5") .withHeaders(CACHE_CONTROL -> "max-age=5")
}, },
api = _ => { api = _ => {

View file

@ -1,4 +1,4 @@
@(u: User, playing: Option[Pov], blocked: Boolean, followable: Boolean, rel: Option[lila.relation.Relation], crosstable: Option[lila.game.Crosstable])(implicit ctx: Context) @(u: User, playing: Option[Pov], blocked: Boolean, followable: Boolean, rel: Option[lila.relation.Relation], ping: Option[Int], crosstable: Option[lila.game.Crosstable])(implicit ctx: Context)
<div class="title"> <div class="title">
<div> <div>
@u.profileOrDefault.countryInfo.map { @u.profileOrDefault.countryInfo.map {
@ -9,6 +9,7 @@
</span> </span>
} }
} }
@ping.map { p => <span class="ping">@p</span> }
@userLink(u, withPowerTip = false) @userLink(u, withPowerTip = false)
</div> </div>
@if(u.engine && ctx.me.fold(true)(u !=)) { @if(u.engine && ctx.me.fold(true)(u !=)) {

View file

@ -85,8 +85,13 @@ abstract class SocketActor[M <: SocketMember](uidTtl: Duration) extends Socket w
def ping(uid: String, lagTenths: Option[Int]) { def ping(uid: String, lagTenths: Option[Int]) {
setAlive(uid) setAlive(uid)
lagTenths foreach { lt => UserLagCache.put(uid, lt) } withMember(uid) { member =>
withMember(uid)(_ push pong) for {
lt <- lagTenths
user <- member.userId
} UserLagCache.put(user, lt)
member push pong
}
} }
def broom { def broom {