preload friend box and show number of friends
This commit is contained in:
parent
01cbd8f2af
commit
59c36bfbae
|
@ -7,7 +7,7 @@ import play.api.templates.Html
|
|||
|
||||
trait AssetHelper {
|
||||
|
||||
val assetVersion = 2
|
||||
val assetVersion = 3
|
||||
|
||||
def cssTag(name: String) = css("stylesheets/" + name)
|
||||
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package lila.app
|
||||
package templating
|
||||
|
||||
import akka.pattern.ask
|
||||
import play.api.libs.json._
|
||||
|
||||
import lila.hub.actorApi.relation._
|
||||
import lila.relation.Relation
|
||||
import lila.user.Context
|
||||
import makeTimeout.short
|
||||
|
||||
trait RelationHelper {
|
||||
|
||||
|
@ -13,4 +18,13 @@ trait RelationHelper {
|
|||
|
||||
def followsMe(userId: String)(implicit ctx: Context): Boolean =
|
||||
ctx.userId ?? { api.follows(userId, _).await }
|
||||
|
||||
def onlineFriends(userId: String): JsObject = {
|
||||
Env.hub.actor.relation ? GetOnlineFriends(userId) map {
|
||||
case OnlineFriends(usernames, nb) ⇒ Json.obj(
|
||||
"us" -> usernames,
|
||||
"nb" -> nb
|
||||
)
|
||||
}
|
||||
}.await
|
||||
}
|
||||
|
|
|
@ -128,8 +128,8 @@ moreJs: Html = Html(""))(body: Html)(implicit ctx: Context)
|
|||
</div>
|
||||
</div>
|
||||
@ctx.me.map { me =>
|
||||
<div id="friend_box">
|
||||
<div class="title">@onlineFriends.friends() (<strong> </strong>)</div>
|
||||
<div id="friend_box" data-preload="@onlineFriends(me.id)">
|
||||
<div class="title">@trans.onlineFriends() - <strong class="online"> </strong>/<span class="total"> </span></div>
|
||||
<div class="content list"></div>
|
||||
<div class="nobody">
|
||||
<span>@trans.noFriendsOnline()</span>
|
||||
|
|
|
@ -122,5 +122,7 @@ package bookmark {
|
|||
}
|
||||
|
||||
package relation {
|
||||
case class ReloadFollowing(userId: String)
|
||||
case class ReloadOnlineFriends(userId: String)
|
||||
case class GetOnlineFriends(userId: String)
|
||||
case class OnlineFriends(usernames: List[String], nb: Int)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.relation
|
|||
|
||||
import akka.actor.Actor
|
||||
import akka.pattern.{ ask, pipe }
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import actorApi._
|
||||
import lila.hub.actorApi.relation._
|
||||
|
@ -22,9 +23,15 @@ private[relation] final class RelationActor(
|
|||
def receive = {
|
||||
|
||||
// triggers following reloading for this user id
|
||||
case ReloadFollowing(userId) ⇒ api.following(userId) flatMap { ids ⇒
|
||||
((ids intersect onlineIds).toList map getUsername).sequenceFu
|
||||
} map { SendTo(userId, "following_onlines", _) } pipeTo socketHub.ref
|
||||
case ReloadOnlineFriends(userId) ⇒ onlineFriends(userId) map {
|
||||
case OnlineFriends(usernames, nb) ⇒
|
||||
SendTo(userId, "following_onlines", Json.obj(
|
||||
"us" -> usernames,
|
||||
"nb" -> nb
|
||||
))
|
||||
} pipeTo socketHub.ref
|
||||
|
||||
case GetOnlineFriends(userId) ⇒ onlineFriends(userId) pipeTo sender
|
||||
|
||||
case NotifyMovement ⇒ {
|
||||
val prevIds = onlineIds
|
||||
|
@ -50,6 +57,11 @@ private[relation] final class RelationActor(
|
|||
private var onlines = Map[ID, Username]()
|
||||
private def onlineIds: Set[ID] = onlines.keySet
|
||||
|
||||
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)
|
||||
|
||||
private def notifyFollowers(users: List[User], message: String) {
|
||||
users foreach {
|
||||
case (id, name) ⇒ api.followers(id) foreach { ids ⇒
|
||||
|
|
|
@ -3,7 +3,7 @@ package lila.relation
|
|||
import lila.db.api._
|
||||
import lila.db.Implicits._
|
||||
import lila.game.GameRepo
|
||||
import lila.hub.actorApi.relation.ReloadFollowing
|
||||
import lila.hub.actorApi.relation.ReloadOnlineFriends
|
||||
import lila.hub.actorApi.timeline.{ Propagate, Follow ⇒ FollowUser }
|
||||
import lila.hub.ActorLazyRef
|
||||
import lila.user.tube.userTube
|
||||
|
@ -65,5 +65,5 @@ final class RelationApi(
|
|||
|
||||
private def refresh(u1: ID, u2: ID): Funit =
|
||||
cached.invalidate(u1, u2) >>-
|
||||
List(u1, u2).foreach(actor ! ReloadFollowing(_))
|
||||
List(u1, u2).foreach(actor ! ReloadOnlineFriends(_))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import play.api.libs.json._
|
|||
|
||||
import actorApi._
|
||||
import lila.common.PimpedJson._
|
||||
import lila.hub.actorApi.relation.ReloadFollowing
|
||||
import lila.hub.actorApi.relation.ReloadOnlineFriends
|
||||
import makeTimeout.large
|
||||
|
||||
object Handler {
|
||||
|
@ -25,7 +25,7 @@ object Handler {
|
|||
val baseController: Controller = {
|
||||
case ("p", _) ⇒ socket ! Ping(uid)
|
||||
case ("following_onlines", _) ⇒ userId foreach { u ⇒
|
||||
hub.actor.relation ! ReloadFollowing(u)
|
||||
hub.actor.relation ! ReloadOnlineFriends(u)
|
||||
}
|
||||
case msg ⇒ logwarn("Unhandled msg: " + msg)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
|
|||
offlineTag: false, // jQuery object showing connection error
|
||||
pingMaxLag: 8000, // time to wait for pong before reseting the connection
|
||||
pingDelay: 1500, // time between pong and ping
|
||||
syncFriendsDelay: 60 * 1000, // time between two syncs
|
||||
lagTag: false, // jQuery object showing ping lag
|
||||
ignoreUnknownMessages: false
|
||||
}
|
||||
|
@ -40,7 +39,6 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
|
|||
self.fullUrl = null;
|
||||
self.pingSchedule = null;
|
||||
self.connectSchedule = null;
|
||||
self.syncFriendsSchedule = null;
|
||||
self.lastPingTime = self.now();
|
||||
self.currentLag = 0;
|
||||
self.averageLag = 0;
|
||||
|
@ -68,7 +66,6 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
|
|||
self.onSuccess();
|
||||
if (self.options.offlineTag) self.options.offlineTag.hide();
|
||||
self.pingNow();
|
||||
self.syncFriends();
|
||||
$('body').trigger('socket.open');
|
||||
};
|
||||
self.ws.onmessage = function(e) {
|
||||
|
@ -144,16 +141,6 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
|
|||
v: this.version
|
||||
});
|
||||
},
|
||||
syncFriends: function() {
|
||||
var self = this;
|
||||
clearTimeout(self.syncFriendsSchedule);
|
||||
self.syncFriendsSchedule = setTimeout(function() {
|
||||
self.syncFriends();
|
||||
}, self.options.syncFriendsDelay);
|
||||
this.ws.send(JSON.stringify({
|
||||
t: "following_onlines"
|
||||
}));
|
||||
},
|
||||
handle: function(m) {
|
||||
var self = this;
|
||||
if (m.v) {
|
||||
|
@ -1274,25 +1261,30 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
|
|||
|
||||
$.widget("lichess.friends", {
|
||||
_create: function() {
|
||||
this.nb = this.element.find('.title strong');
|
||||
this.list = this.element.find("div.list");
|
||||
this.nobody = this.element.find("div.nobody");
|
||||
this.$nbOnline = this.element.find('.title .online');
|
||||
this.$nbTotal = this.element.find('.title .total');
|
||||
this.$list = this.element.find("div.list");
|
||||
this.$nobody = this.element.find("div.nobody");
|
||||
this.nb = 0;
|
||||
this.set(this.element.data('preload'));
|
||||
},
|
||||
repaint: function() {
|
||||
var nb = this.list.children().length;
|
||||
this.nb.text(nb);
|
||||
this.nobody.toggle(nb == 0);
|
||||
var onlineNb = this.$list.children().length;
|
||||
this.$nbOnline.text(onlineNb);
|
||||
this.$nbTotal.text(this.nb);
|
||||
this.$nobody.toggle(onlineNb == 0);
|
||||
},
|
||||
set: function(users) {
|
||||
this.list.html(_.map(users, this._renderUser).join(""));
|
||||
set: function(data) {
|
||||
this.nb = data['nb'];
|
||||
this.$list.html(_.map(data['us'], this._renderUser).join(""));
|
||||
this.repaint();
|
||||
},
|
||||
enters: function(user) {
|
||||
this.list.append(this._renderUser(user));
|
||||
this.$list.append(this._renderUser(user));
|
||||
this.repaint();
|
||||
},
|
||||
leaves: function(user) {
|
||||
this.list.children().filter(function() {
|
||||
this.$list.children().filter(function() {
|
||||
return $(this).text() == user;
|
||||
}).remove();
|
||||
this.repaint();
|
||||
|
@ -1858,7 +1850,7 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
|
|||
function resizeTimeline() {
|
||||
var max = $('#lichess').offset().top + 512;
|
||||
var pos = $timeline.offset().top;
|
||||
while(pos + $timeline.outerHeight() > max) {
|
||||
while (pos + $timeline.outerHeight() > max) {
|
||||
$timeline.find('div:last').remove();
|
||||
}
|
||||
}
|
||||
|
|
1
todo
1
todo
|
@ -79,6 +79,7 @@ LilaError['[analysis] fred65 already analyses ueogn4fr, won't process ueogn4fr']
|
|||
1024 compat (timeline)
|
||||
online glitch http://en.lichess.org/forum/lichess-feedback/migration-to-new-codebase?page=4#32
|
||||
friend box text: "Online friends (x/y)"
|
||||
check that draw games impact elo
|
||||
|
||||
DEPLOY p21
|
||||
----------
|
||||
|
|
Loading…
Reference in a new issue