Display ping on powertip

showPingInPowertip
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 scala.concurrent.duration._
import chess.Centis
import lila.api.BodyContext
import lila.app._
import lila.app.mashup.GameFilterMenu
@ -12,6 +13,7 @@ import lila.common.{ IpAddress, HTTPRequest }
import lila.game.{ GameRepo, Game => GameModel }
import lila.rating.PerfType
import lila.user.{ User => UserModel, UserRepo }
import lila.socket.UserLagCache
import views._
object User extends LilaController {
@ -46,6 +48,13 @@ object User extends LilaController {
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 =>
OptionFuResult(UserRepo named username) { user =>
if (user.enabled) for {
@ -53,9 +62,10 @@ object User extends LilaController {
crosstable <- ctx.userId ?? { Env.game.crosstableApi(user.id, _) }
followable <- ctx.isAuth ?? { Env.pref.api.followable(user.id) }
relation <- ctx.userId ?? { relationApi.fetchRelation(_, user.id) }
ping = UserLagCache.get(user.id) map connQuality
res <- negotiate(
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")
},
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>
@u.profileOrDefault.countryInfo.map {
@ -9,6 +9,7 @@
</span>
}
}
@ping.map { p => <span class="ping">@p</span> }
@userLink(u, withPowerTip = false)
</div>
@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]) {
setAlive(uid)
lagTenths foreach { lt => UserLagCache.put(uid, lt) }
withMember(uid)(_ push pong)
withMember(uid) { member =>
for {
lt <- lagTenths
user <- member.userId
} UserLagCache.put(user, lt)
member push pong
}
}
def broom {