show all followers in friend box

This commit is contained in:
Thibault Duplessis 2013-05-27 17:01:09 +02:00
parent 892ac89255
commit d40c014f5a
7 changed files with 21 additions and 20 deletions

View file

@ -117,5 +117,5 @@ package bookmark {
}
package relation {
case class ReloadFriends(userId: String)
case class ReloadFollowing(userId: String)
}

View file

@ -40,7 +40,7 @@ final class Env(
socketHub = hub.socket.hub,
getOnlineUserIds = getOnlineUserIds,
getUsername = getUsername,
getFriendIds = cached.friends.apply
api = api
)), name = ActorName)
{

View file

@ -13,7 +13,7 @@ private[relation] final class RelationActor(
socketHub: ActorLazyRef,
getOnlineUserIds: () Set[String],
getUsername: String Fu[String],
getFriendIds: String Fu[Set[String]]) extends Actor {
api: RelationApi) extends Actor {
private type ID = String
private type Username = String
@ -21,10 +21,10 @@ private[relation] final class RelationActor(
def receive = {
// triggers friends reloading for this user id
case ReloadFriends(userId) getFriendIds(userId) flatMap { ids
// 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, "friends", _) } pipeTo socketHub.ref
} map { SendTo(userId, "following_onlines", _) } pipeTo socketHub.ref
case NotifyMovement {
val prevIds = onlineIds
@ -42,17 +42,17 @@ private[relation] final class RelationActor(
onlines = onlines -- leaveIds ++ enters
notifyFriends(enters, "friend_enters")
notifyFriends(leaves, "friend_leaves")
notifyFollowers(enters, "following_enters")
notifyFollowers(leaves, "following_leaves")
}
}
private var onlines = Map[ID, Username]()
private def onlineIds: Set[ID] = onlines.keySet
private def notifyFriends(users: List[User], message: String) {
private def notifyFollowers(users: List[User], message: String) {
users foreach {
case (id, name) getFriendIds(id) foreach { ids
case (id, name) api.followers(id) foreach { ids
val notify = ids filter onlines.contains
if (notify.nonEmpty) socketHub ! SendTos(notify.toSet, message, name)
}

View file

@ -3,7 +3,7 @@ package lila.relation
import lila.db.api._
import lila.db.Implicits._
import lila.game.GameRepo
import lila.hub.actorApi.relation.ReloadFriends
import lila.hub.actorApi.relation.ReloadFollowing
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 ! ReloadFriends(_))
List(u1, u2).foreach(actor ! ReloadFollowing(_))
}

View file

@ -7,7 +7,7 @@ import play.api.libs.json._
import actorApi._
import lila.common.PimpedJson._
import lila.hub.actorApi.relation.ReloadFriends
import lila.hub.actorApi.relation.ReloadFollowing
import makeTimeout.large
object Handler {
@ -24,8 +24,8 @@ object Handler {
val baseController: Controller = {
case ("p", _) socket ! Ping(uid)
case ("friends", _) userId foreach { u
hub.actor.relation ! ReloadFriends(u)
case ("following_onlines", _) userId foreach { u
hub.actor.relation ! ReloadFollowing(u)
}
case msg logwarn("Unhandled msg: " + msg)
}

View file

@ -147,7 +147,7 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
self.syncFriends();
}, self.options.syncFriendsDelay);
this.ws.send(JSON.stringify({
t: "friends"
t: "following_onlines"
}));
},
handle: function(m) {
@ -227,13 +227,13 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
socket: null,
socketDefaults: {
events: {
friends: function(data) {
following_onlines: function(data) {
$('#friend_box').friends("set", data);
},
friend_enters: function(name) {
following_enters: function(name) {
$('#friend_box').friends('enters', name);
},
friend_leaves: function(name) {
following_leaves: function(name) {
$('#friend_box').friends('leaves', name);
},
n: function(e) {
@ -1274,7 +1274,7 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
this.repaint();
},
enters: function(user) {
this.list.append(renderUser(user));
this.list.append(_renderUser(user));
this.repaint();
},
leaves: function(user) {

1
todo
View file

@ -71,6 +71,7 @@ takeback/enpassant glitch http://en.lichess.org/forum/lichess-feedback/i-found-a
show teams in user mini
badges for top players in ELO and number of games
top menu is too long in french with long username
have a forum post redirection instead of assuming the last topic page - applies to search and timelines
DEPLOY p21
----------