implement ornicar's suggestions.

pull/2068/head
Gordon Martin 2016-07-04 21:41:08 +01:00
parent 3829f28180
commit 9ae946a759
6 changed files with 20 additions and 14 deletions

View File

@ -305,7 +305,7 @@ private[controllers] trait LilaController
import makeTimeout.short
(Env.hub.actor.relation ? GetOnlineFriends(me.id) map {
case OnlineFriends(users, usersPlaying) => (users, usersPlaying)
} recover { case _ => (Nil,Nil) }) zip
} recover { case _ => (Nil,Set.empty[String]) }) zip
Env.team.api.nbRequests(me.id) zip
Env.challenge.api.countInFor(me.id) zip
Env.notifyModule.api.unreadCount(Notifies(me.id)).map(_.value)

View File

@ -169,7 +169,8 @@ withLangAnnotations: Boolean = true)(body: Html)(implicit ctx: Context)
</div>
</div>
@ctx.me.map { me =>
<div id="friend_box" data-preload="@ctx.friends.map(_.titleName).mkString(",")" data-playing="@ctx.friendsPlaying.map(_.titleName).mkString(",")" >
<div id="friend_box" data-preload="@ctx.friends.map(_.titleName).mkString(",")"
data-playing="@ctx.friendsPlaying.mkString(",")" >
<div class="title"><strong class="online"> </strong> @trans.onlineFriends()</div>
<div class="content_wrap">
<div class="content list"></div>

View File

@ -8,7 +8,7 @@ import lila.user.{ UserContext, HeaderUserContext, BodyUserContext }
case class PageData(
friends: List[lila.common.LightUser],
friendsPlaying: List[lila.common.LightUser],
friendsPlaying: Set[String],
teamNbRequests: Int,
nbChallenges: Int,
nbNotifications: Int,
@ -18,7 +18,7 @@ case class PageData(
object PageData {
val default = PageData(Nil, Nil, 0, 0, 0, Pref.default, false, false)
val default = PageData(Nil, Set.empty, 0, 0, 0, Pref.default, false, false)
def anon(blindMode: Boolean) = default.copy(blindMode = blindMode)
}

View File

@ -185,7 +185,7 @@ case class Remove(gameId: String)
package relation {
case class ReloadOnlineFriends(userId: String)
case class GetOnlineFriends(userId: String)
case class OnlineFriends(users: List[LightUser], usersPlaying: List[LightUser])
case class OnlineFriends(users: List[LightUser], usersPlaying: Set[String])
case class Block(u1: String, u2: String)
case class UnBlock(u1: String, u2: String)
}

View File

@ -21,7 +21,7 @@ private[relation] final class RelationActor(
private var onlines = Map[ID, LightUser]()
private var onlinePlayings = Map[ID, LightUser]()
private var onlinePlayings = Set[ID]()
override def preStart(): Unit = {
context.system.lilaBus.subscribe(self, 'startGame)
@ -41,7 +41,7 @@ private[relation] final class RelationActor(
case ReloadOnlineFriends(userId) => onlineFriends(userId) foreach {
case OnlineFriends(users, friendsPlaying) =>
bus.publish(SendTo(userId, "following_onlines", users.map(_.titleName)), 'users)
bus.publish(SendTo(userId, "following_playings", friendsPlaying.map(_.titleName)), 'users)
bus.publish(SendTo(userId, "following_playings", friendsPlaying), 'users)
}
case NotifyMovement =>
@ -62,7 +62,7 @@ private[relation] final class RelationActor(
case msg: lila.game.actorApi.StartGame =>
val usersPlaying = getGameUsers(msg.game)
onlinePlayings = onlinePlayings ++ usersPlaying.map(u => u.id -> u)
onlinePlayings = onlinePlayings ++ usersPlaying.map(_.id)
notifyFollowers(usersPlaying, "following_playing")
}
@ -80,8 +80,8 @@ private[relation] final class RelationActor(
OnlineFriends(friends, friendsPlaying)
}
private def getFriendsPlaying(friends: List[LightUser]): List[LightUser] = {
friends.filter(p => onlinePlayings.contains(p.id))
private def getFriendsPlaying(friends: List[LightUser]): Set[String] = {
friends.filter(p => onlinePlayings.contains(p.id)).map(_.id).toSet
}
private def notifyFollowers(users: List[LightUser], message: String) {

View File

@ -1154,12 +1154,17 @@ lichess.notifyApp = (function() {
},
_setPlaying: function(userName, playing) {
var user = this.users.find(function(u) {
return u.name === userName;
var isSameUser = function(userName, user) {
var id = $.fp.contains(user.name, ' ') ? user.name.split(' ')[1] : user.name;
return id === userName;
}
var user = this.users.filter(function(u) {
return isSameUser(userName, u);
});
if (user) {
user["playing"] = playing;
if (user.length > 0) {
user[0]["playing"] = playing;
}
},