implement ornicar's suggestions.
This commit is contained in:
parent
3829f28180
commit
9ae946a759
|
@ -305,7 +305,7 @@ private[controllers] trait LilaController
|
||||||
import makeTimeout.short
|
import makeTimeout.short
|
||||||
(Env.hub.actor.relation ? GetOnlineFriends(me.id) map {
|
(Env.hub.actor.relation ? GetOnlineFriends(me.id) map {
|
||||||
case OnlineFriends(users, usersPlaying) => (users, usersPlaying)
|
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.team.api.nbRequests(me.id) zip
|
||||||
Env.challenge.api.countInFor(me.id) zip
|
Env.challenge.api.countInFor(me.id) zip
|
||||||
Env.notifyModule.api.unreadCount(Notifies(me.id)).map(_.value)
|
Env.notifyModule.api.unreadCount(Notifies(me.id)).map(_.value)
|
||||||
|
|
|
@ -169,7 +169,8 @@ withLangAnnotations: Boolean = true)(body: Html)(implicit ctx: Context)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ctx.me.map { me =>
|
@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="title"><strong class="online"> </strong> @trans.onlineFriends()</div>
|
||||||
<div class="content_wrap">
|
<div class="content_wrap">
|
||||||
<div class="content list"></div>
|
<div class="content list"></div>
|
||||||
|
|
|
@ -8,7 +8,7 @@ import lila.user.{ UserContext, HeaderUserContext, BodyUserContext }
|
||||||
|
|
||||||
case class PageData(
|
case class PageData(
|
||||||
friends: List[lila.common.LightUser],
|
friends: List[lila.common.LightUser],
|
||||||
friendsPlaying: List[lila.common.LightUser],
|
friendsPlaying: Set[String],
|
||||||
teamNbRequests: Int,
|
teamNbRequests: Int,
|
||||||
nbChallenges: Int,
|
nbChallenges: Int,
|
||||||
nbNotifications: Int,
|
nbNotifications: Int,
|
||||||
|
@ -18,7 +18,7 @@ case class PageData(
|
||||||
|
|
||||||
object 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)
|
def anon(blindMode: Boolean) = default.copy(blindMode = blindMode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ case class Remove(gameId: String)
|
||||||
package relation {
|
package relation {
|
||||||
case class ReloadOnlineFriends(userId: String)
|
case class ReloadOnlineFriends(userId: String)
|
||||||
case class GetOnlineFriends(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 Block(u1: String, u2: String)
|
||||||
case class UnBlock(u1: String, u2: String)
|
case class UnBlock(u1: String, u2: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ private[relation] final class RelationActor(
|
||||||
|
|
||||||
private var onlines = Map[ID, LightUser]()
|
private var onlines = Map[ID, LightUser]()
|
||||||
|
|
||||||
private var onlinePlayings = Map[ID, LightUser]()
|
private var onlinePlayings = Set[ID]()
|
||||||
|
|
||||||
override def preStart(): Unit = {
|
override def preStart(): Unit = {
|
||||||
context.system.lilaBus.subscribe(self, 'startGame)
|
context.system.lilaBus.subscribe(self, 'startGame)
|
||||||
|
@ -41,7 +41,7 @@ private[relation] final class RelationActor(
|
||||||
case ReloadOnlineFriends(userId) => onlineFriends(userId) foreach {
|
case ReloadOnlineFriends(userId) => onlineFriends(userId) foreach {
|
||||||
case OnlineFriends(users, friendsPlaying) =>
|
case OnlineFriends(users, friendsPlaying) =>
|
||||||
bus.publish(SendTo(userId, "following_onlines", users.map(_.titleName)), 'users)
|
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 =>
|
case NotifyMovement =>
|
||||||
|
@ -62,7 +62,7 @@ private[relation] final class RelationActor(
|
||||||
|
|
||||||
case msg: lila.game.actorApi.StartGame =>
|
case msg: lila.game.actorApi.StartGame =>
|
||||||
val usersPlaying = getGameUsers(msg.game)
|
val usersPlaying = getGameUsers(msg.game)
|
||||||
onlinePlayings = onlinePlayings ++ usersPlaying.map(u => u.id -> u)
|
onlinePlayings = onlinePlayings ++ usersPlaying.map(_.id)
|
||||||
notifyFollowers(usersPlaying, "following_playing")
|
notifyFollowers(usersPlaying, "following_playing")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ private[relation] final class RelationActor(
|
||||||
OnlineFriends(friends, friendsPlaying)
|
OnlineFriends(friends, friendsPlaying)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getFriendsPlaying(friends: List[LightUser]): List[LightUser] = {
|
private def getFriendsPlaying(friends: List[LightUser]): Set[String] = {
|
||||||
friends.filter(p => onlinePlayings.contains(p.id))
|
friends.filter(p => onlinePlayings.contains(p.id)).map(_.id).toSet
|
||||||
}
|
}
|
||||||
|
|
||||||
private def notifyFollowers(users: List[LightUser], message: String) {
|
private def notifyFollowers(users: List[LightUser], message: String) {
|
||||||
|
|
|
@ -1154,12 +1154,17 @@ lichess.notifyApp = (function() {
|
||||||
},
|
},
|
||||||
_setPlaying: function(userName, playing) {
|
_setPlaying: function(userName, playing) {
|
||||||
|
|
||||||
var user = this.users.find(function(u) {
|
var isSameUser = function(userName, user) {
|
||||||
return u.name === userName;
|
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) {
|
if (user.length > 0) {
|
||||||
user["playing"] = playing;
|
user[0]["playing"] = playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue