<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2372] trunk: Better friendship request usability.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2372</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-19 21:26:59 +0000 (Tue, 19 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Better friendship request usability.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpfriendsbpfriendstemplatetagsphp">trunk/bp-friends/bp-friends-templatetags.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incajaxphp">trunk/bp-themes/bp-default/_inc/ajax.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incglobaljs">trunk/bp-themes/bp-default/_inc/global.js</a></li>
<li><a href="#trunkbpthemesbpdefaultmemberssinglefriendsrequestsphp">trunk/bp-themes/bp-default/members/single/friends/requests.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpfriendsbpfriendstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-templatetags.php (2371 => 2372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-templatetags.php        2010-01-19 20:45:07 UTC (rev 2371)
+++ trunk/bp-friends/bp-friends-templatetags.php        2010-01-19 21:26:59 UTC (rev 2372)
</span><span class="lines">@@ -160,11 +160,23 @@
</span><span class="cx">         return apply_filters( 'bp_get_friendship_requests', implode( ',', (array) friends_get_friendship_request_user_ids( $bp->loggedin_user->id ) ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+function bp_friend_friendship_id() {
+        echo bp_get_friend_friendship_id();
+}
+        function bp_get_friend_friendship_id() {
+                global $members_template, $bp;
+
+                if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
+                        $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
+                        wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
+                }
+
+                return apply_filters( 'bp_get_friend_friendship_id', $friendship_id );
+        }
+
</ins><span class="cx"> function bp_friend_accept_request_link() {
</span><span class="cx">         echo bp_get_friend_accept_request_link();
</span><span class="cx"> }
</span><del>-        // You only have the user ID but you need the friendship ID !!
-
</del><span class="cx">         function bp_get_friend_accept_request_link() {
</span><span class="cx">                 global $members_template, $bp;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/ajax.php (2371 => 2372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/ajax.php        2010-01-19 20:45:07 UTC (rev 2371)
+++ trunk/bp-themes/bp-default/_inc/ajax.php        2010-01-19 21:26:59 UTC (rev 2372)
</span><span class="lines">@@ -352,6 +352,26 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend' );
</span><span class="cx">
</span><ins>+function bp_dtheme_ajax_accept_friendship() {
+        check_admin_referer( 'friends_accept_friendship' );
+
+        if ( !friends_accept_friendship( $_POST['id'] ) )
+                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>';
+
+        return true;
+}
+add_action( 'wp_ajax_accept_friendship', 'bp_dtheme_ajax_accept_friendship' );
+
+function bp_dtheme_ajax_reject_friendship() {
+        check_admin_referer( 'friends_reject_friendship' );
+
+        if ( !friends_reject_friendship( $_POST['id'] ) )
+                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>';
+
+        return true;
+}
+add_action( 'wp_ajax_reject_friendship', 'bp_dtheme_ajax_reject_friendship' );
+
</ins><span class="cx"> function bp_dtheme_ajax_joinleave_group() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incglobaljs"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/global.js (2371 => 2372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/global.js        2010-01-19 20:45:07 UTC (rev 2371)
+++ trunk/bp-themes/bp-default/_inc/global.js        2010-01-19 21:26:59 UTC (rev 2372)
</span><span class="lines">@@ -767,8 +767,54 @@
</span><span class="cx">                 return false;
</span><span class="cx">         });
</span><span class="cx">
</span><del>-        /** Friendship Request Buttons **************************************/
</del><ins>+        /** Friendship Requests **************************************/
</ins><span class="cx">
</span><ins>+        j("ul#friend-list a.accept, ul#friend-list a.reject").click( function() {
+                var button = j(this);
+                var li = j(this).parents('ul#friend-list li');
+                var action_div = j(this).parents('li div.action');
+
+                var id = li.attr('id').substr( 11, li.attr('id').length );
+                var link_href = button.attr('href');
+
+                var nonce = link_href.split('_wpnonce=');
+                        nonce = nonce[1];
+
+                if ( j(this).hasClass('accept') ) {
+                        var action = 'accept_friendship';
+                        action_div.children('a.reject').css( 'visibility', 'hidden' );
+                } else {
+                        var action = 'reject_friendship';
+                        action_div.children('a.accept').css( 'visibility', 'hidden' );
+                }
+
+                button.addClass('loading');
+
+                j.post( ajaxurl, {
+                        action: action,
+                        'cookie': encodeURIComponent(document.cookie),
+                        'id': id,
+                        '_wpnonce': nonce
+                },
+                function(response) {
+                        button.removeClass('loading');
+
+                        if ( response[0] + response[1] == '-1' ) {
+                                li.prepend( response.substr( 2, response.length ) );
+                                li.children('div#message').hide().fadeIn(200);
+                        } else {
+                                button.fadeOut( 100, function() {
+                                        if ( j(this).hasClass('accept') )
+                                                j(this).html( 'Accepted' ).fadeIn(50);
+                                        else
+                                                j(this).html( 'Rejected' ).fadeIn(50);
+                                });
+                        }
+                });
+
+                return false;
+        });
+
</ins><span class="cx">         j("div.friendship-button a").live('click', function() {
</span><span class="cx">                 j(this).parent().addClass('loading');
</span><span class="cx">                 var fid = j(this).attr('id');
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultmemberssinglefriendsrequestsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/members/single/friends/requests.php (2371 => 2372)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/members/single/friends/requests.php        2010-01-19 20:45:07 UTC (rev 2371)
+++ trunk/bp-themes/bp-default/members/single/friends/requests.php        2010-01-19 21:26:59 UTC (rev 2372)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx">         <ul id="friend-list" class="item-list">
</span><span class="cx">                 <?php while ( bp_members() ) : bp_the_member(); ?>
</span><span class="cx">
</span><del>-                        <li>
</del><ins>+                        <li id="friendship-<?php bp_friend_friendship_id() ?>">
</ins><span class="cx">                                 <div class="item-avatar">
</span><span class="cx">                                         <a href="<?php bp_member_link() ?>"><?php bp_member_avatar() ?></a>
</span><span class="cx">                                 </div>
</span><span class="lines">@@ -19,7 +19,7 @@
</span><span class="cx">
</span><span class="cx">                                 <div class="action">
</span><span class="cx">                                         <a class="button accept" href="<?php bp_friend_accept_request_link() ?>"><?php _e( 'Accept', 'buddypress' ); ?></a> &nbsp;
</span><del>-                                        <a class="button reject confirm" href="<?php bp_friend_reject_request_link() ?>"><?php _e( 'Reject', 'buddypress' ); ?></a>
</del><ins>+                                        <a class="button reject" href="<?php bp_friend_reject_request_link() ?>"><?php _e( 'Reject', 'buddypress' ); ?></a>
</ins><span class="cx">
</span><span class="cx">                                         <?php do_action( 'bp_friend_requests_item_action' ) ?>
</span><span class="cx">                                 </div>
</span></span></pre>
</div>
</div>
</body>
</html>