Blurs & under_chat improvements

- Cleanup spectator calculation code
- Show blurs for games in progress
  (lost in ts rewrite of round)
  fixes #3794.
This commit is contained in:
Isaac Levy 2017-11-16 18:46:31 -05:00
parent c49d7d00b6
commit 36fdae55f7
4 changed files with 32 additions and 20 deletions

View file

@ -33,11 +33,17 @@ chat.ChatJsData.json(c.chat, name = trans.chatRoom.txt(), timeout = c.timeout, p
<link href="@routes.Round.atom(pov.gameId, pov.color.name)" type="application/atom+xml" rel="alternate" title="Game feed" />
}
@underchat = {
@views.html.game.watchers()
@round.blurs(pov.game)
@round.holdAlerts(pov.game)
}
@round.layout(
title = title,
side = views.html.game.side(pov, (data\"game"\"initialFen").asOpt[String], tour.map(_.tour), simul, bookmarked = bookmarked),
chat = chatOption.isDefined.option(chat.dom()),
underchat = views.html.game.watchers().some,
underchat = underchat.some,
moreJs = moreJs,
moreCss = cssTag("chat.css"),
openGraph = povOpenGraph(pov).some,

View file

@ -22,11 +22,17 @@ chat.ChatJsData.json(c.chat, name = trans.spectatorRoom.txt(), timeout = c.timeo
<link href="@routes.Round.atom(pov.gameId, pov.color.name)" type="application/atom+xml" rel="alternate" title="Game feed" />
}
@underchat = {
@views.html.game.watchers()
@round.blurs(pov.game)
@round.holdAlerts(pov.game)
}
@round.layout(
title = title,
side = views.html.game.side(pov, (data\"game"\"initialFen").asOpt[String], tour.map(_.tour), simul = simul, userTv = userTv, bookmarked = bookmarked),
chat = chat.dom().some,
underchat = views.html.game.watchers().some,
underchat = underchat.some,
moreJs = moreJs,
moreCss = cssTag("chat.css"),
openGraph = povOpenGraph(pov).some,

View file

@ -166,27 +166,26 @@ abstract class SocketActor[M <: SocketMember](uidTtl: Duration) extends Socket w
def uidToUserId(uid: Socket.Uid): Option[String] = members get uid.value flatMap (_.userId)
val maxSpectatorUsers = 10
val maxSpectatorUsers = 15
def showSpectators(lightUser: LightUser.Getter)(watchers: Iterable[SocketMember]): Fu[JsValue] = {
def showSpectators(lightUser: LightUser.Getter)(watchers: Iterable[SocketMember]): Fu[JsValue] = watchers.size match {
case 0 => fuccess(JsNull)
case s if s > maxSpectatorUsers => fuccess(Json.obj("nb" -> s))
case s => {
val userIdsWithDups = watchers.toSeq.flatMap(_.userId)
val anons = s - userIdsWithDups.size
val userIds = userIdsWithDups.distinct
val (total, anons, userIds) = watchers.foldLeft((0, 0, Set.empty[String])) {
case ((total, anons, userIds), member) => member.userId match {
case Some(userId) if !userIds(userId) && userIds.size < maxSpectatorUsers => (total + 1, anons, userIds + userId)
case Some(_) => (total + 1, anons, userIds)
case _ => (total + 1, anons + 1, userIds)
val total = anons + userIds.size
userIds.map(lightUser).sequenceFu.map { users =>
Json.obj(
"nb" -> total,
"users" -> users.flatten.map(_.titleName),
"anons" -> anons
)
}
}
if (total == 0) fuccess(JsNull)
else if (userIds.size >= maxSpectatorUsers) fuccess(Json.obj("nb" -> total))
else userIds.map(lightUser).sequenceFu.map { users =>
Json.obj(
"nb" -> total,
"users" -> users.flatten.map(_.titleName),
"anons" -> anons
)
}
}
def withMember(uid: String)(f: M => Unit): Unit = {

View file

@ -965,7 +965,8 @@ div.under_chat .watchers {
margin-top: 10px;
opacity: 0.65;
transition: 0.13s;
height: 9em;
min-height: 5em;
max-height: 9em;
overflow: hidden;
}
div.under_chat .watchers.hidden {