improve friendship creation/revokation

pull/83/head
Thibault Duplessis 2013-05-20 16:29:12 -03:00
parent b008fd686c
commit cb0f665f33
7 changed files with 23 additions and 18 deletions

View File

@ -1,18 +1,21 @@
@(userId: String)(implicit ctx: Context)
<div class="friend_button">
@friendStatus(userId).map { status =>
@if(status.friends) {
<span class="friend_button">@trans.friends()</span>
@trans.friends()
} else {
@if(status.pending) {
<span class="friend_button">@trans.pendingRequest</span>
@trans.pendingRequest()
<a class="friend_button" href="@routes.Friend.no(userId)">@trans.cancel()</a>
} else {
@if(status.requested) {
<a class="friend_button" href="@routes.Friend.yes(userId)">@trans.accept()</a>
<a class="friend_button" href="@routes.Friend.no(userId)">@trans.decline()</a>
<a href="@routes.Friend.yes(userId)">@trans.accept()</a>
<a href="@routes.Friend.no(userId)">@trans.decline()</a>
} else {
<a class="friend_button" href="@routes.Friend.yes(userId)">@trans.addFriend()</a>
<a href="@routes.Friend.yes(userId)">@trans.addFriend()</a>
}
}
}
}
</div>

View File

@ -11,4 +11,9 @@ private[friend] final class Cached {
val requestIds = AsyncCache(RequestRepo.requestedUserIds, maxCapacity = 5000)
val nbRequests = AsyncCache(RequestRepo.countByFriendId, maxCapacity = 5000)
private[friend] def invalidate(userId: ID): Funit =
friendIds.remove(userId) >>
requestIds.remove(userId) >>
nbRequests.remove(userId)
}

View File

@ -23,7 +23,7 @@ final class FriendApi(cached: Cached) {
case ((_, true), _) QuickStatus(u1, u2, false, true.some)
case ((_, _), true) QuickStatus(u1, u2, false, false.some)
case _ QuickStatus(u1, u2, false, none)
}
}
def friendsOf(userId: ID): Fu[List[User]] =
cached friendIds userId flatMap UserRepo.byIds map { _ sortBy (_.id) }
@ -64,9 +64,5 @@ final class FriendApi(cached: Cached) {
accept ?? makeFriends(request.user, request.friend)
private def invalidate(userIds: String*): Funit =
userIds.toList.map(userId
cached.friendIds.remove(userId) >>
cached.requestIds.remove(userId) >>
cached.nbRequests.remove(userId)
).sequence.void
userIds.toList.map(cached.invalidate).sequence.void
}

View File

@ -18,7 +18,7 @@ private[friend] object FriendRepo {
_.flatten filterNot (userId ==)
}
def add(u1: ID, u2: ID): Funit = $insert(Friend.make(u1, u2))
def add(u1: ID, u2: ID): Funit = $insert(Friend.make(u1, u2).pp)
def remove(u1: ID, u2: ID): Funit = $remove byId Friend.makeId(u1, u2)
}

View File

@ -6,7 +6,7 @@ case class QuickStatus(
friends: Boolean,
request: Option[Boolean]) {
def requested = ~request
def pending = request == Some(true)
def pending = request == Some(false)
def requested = request == Some(false)
}

View File

@ -309,12 +309,12 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
$('#friend_box').friends();
$('#lichess').on('click', 'a.friend_button', function() {
var $button = $(this);
$('#lichess').on('click', 'div.friend_button a', function() {
var $a = $(this).text('...');
$.ajax({
url: $button.attr('href'),
url: $a.attr('href'),
type: 'post',
success: function(html) { $button.replaceWith(html); }
success: function(html) { $a.parent().replaceWith(html); }
});
return false;
});

1
todo
View File

@ -65,6 +65,7 @@ from MoralIntentions email:
- Several options of how points should be given to players (for example: Score * Sonneborn-Berger * Tournament Performance Rating * Percentage Score [for example: 0.64] / 1000) and therefore also several Leaderboards.
- The possibility of team matches (with solutions for players who are in several teams), where the team leader has to choose the board order, where the team results are shown and where the team player (who has played all of the games of the match) with the highest Percentage Score gets crowned Player of the Match of team "A".
safari has high bounce rate
send message to sockets when a friendship is created or revoked
DEPLOY p21
----------