simplify friend box
This commit is contained in:
parent
9d4223d9d9
commit
c4a5332f3f
|
@ -187,7 +187,7 @@ private[controllers] trait LilaController
|
|||
import akka.pattern.ask
|
||||
import makeTimeout.short
|
||||
Env.hub.actor.relation ? GetOnlineFriends(me.id) map {
|
||||
case OnlineFriends(usernames, nb) => Json.obj("us" -> usernames, "nb" -> nb).some
|
||||
case OnlineFriends(usernames) => Json.arr(usernames).some
|
||||
}
|
||||
}
|
||||
} zip {
|
||||
|
|
|
@ -181,7 +181,7 @@ zen: Boolean = false)(body: Html)(implicit ctx: Context)
|
|||
}
|
||||
@ctx.me.map { me =>
|
||||
<div id="friend_box" data-preload="@ctx.friends">
|
||||
<div class="title">@trans.onlineFriends() - <strong class="online"> </strong>/<span class="total"> </span></div>
|
||||
<div class="title"><strong class="online"> </strong> @trans.onlineFriends()</div>
|
||||
<div class="content_wrap">
|
||||
<div class="content list"></div>
|
||||
<div class="nobody">
|
||||
|
|
|
@ -7,7 +7,7 @@ import lila.pref.Pref
|
|||
import lila.user.{ UserContext, HeaderUserContext, BodyUserContext }
|
||||
|
||||
case class PageData(
|
||||
friends: Option[JsObject],
|
||||
friends: Option[JsArray],
|
||||
pref: Pref,
|
||||
teams: Option[JsArray])
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ case class Remove(gameIds: List[String])
|
|||
package relation {
|
||||
case class ReloadOnlineFriends(userId: String)
|
||||
case class GetOnlineFriends(userId: String)
|
||||
case class OnlineFriends(usernames: List[String], nb: Int)
|
||||
case class OnlineFriends(usernames: List[String])
|
||||
case class Block(u1: String, u2: String)
|
||||
case class UnBlock(u1: String, u2: String)
|
||||
}
|
||||
|
|
|
@ -65,17 +65,12 @@ private[relation] final class RelationActor(
|
|||
private def onlineFriends(userId: String): Fu[OnlineFriends] = for {
|
||||
ids ← api following userId
|
||||
usernames ← ((ids intersect onlineIds).toList map getUsername).sequenceFu
|
||||
} yield OnlineFriends(usernames, ids.size)
|
||||
} yield OnlineFriends(usernames)
|
||||
|
||||
private def reloadOnlineFriends(userId: String) {
|
||||
onlineFriends(userId) foreach {
|
||||
case OnlineFriends(usernames, nb) => {
|
||||
val event = SendTo(userId, "following_onlines", Json.obj(
|
||||
"us" -> usernames,
|
||||
"nb" -> nb
|
||||
))
|
||||
bus.publish(event, 'users)
|
||||
}
|
||||
case OnlineFriends(usernames) =>
|
||||
bus.publish(SendTo(userId, "following_onlines", usernames), 'users)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -342,8 +342,8 @@ var storage = {
|
|||
socket: null,
|
||||
socketDefaults: {
|
||||
events: {
|
||||
following_onlines: function(data) {
|
||||
$('#friend_box').friends("set", data);
|
||||
following_onlines: function(us) {
|
||||
$('#friend_box').friends("set", us);
|
||||
},
|
||||
following_enters: function(name) {
|
||||
$('#friend_box').friends('enters', name);
|
||||
|
@ -1593,21 +1593,18 @@ var storage = {
|
|||
});
|
||||
if (storage.get('friends-hide') == 1) self.$title.click();
|
||||
self.$nbOnline = self.$title.find('.online');
|
||||
self.$nbTotal = self.$title.find('.total');
|
||||
self.$nobody = self.element.find("div.nobody");
|
||||
self.set(self.element.data('preload'));
|
||||
},
|
||||
repaint: function() {
|
||||
this.users = _.uniq(this.users);
|
||||
this.$nbOnline.text(this.users.length);
|
||||
this.$nbTotal.text(this.nb);
|
||||
this.$nobody.toggle(this.users.length === 0);
|
||||
this.$list.html(_.map(this.users, this._renderUser).join(""));
|
||||
$('body').trigger('lichess.content_loaded');
|
||||
},
|
||||
set: function(data) {
|
||||
this.nb = data.nb;
|
||||
this.users = data.us;
|
||||
set: function(us) {
|
||||
this.users = us;
|
||||
this.repaint();
|
||||
},
|
||||
enters: function(user) {
|
||||
|
|
Loading…
Reference in a new issue