<!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" />
<title>[BuddyPress][7374] trunk: Rework "Cancel Friendship Request" button UX in member directories</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7374">7374</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2013-09-07 01:02:33 +0000 (Sat, 07 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Rework "Cancel Friendship Request" button UX in member directories
Member directories have friendship action buttons for each user: notably,
Add Friend for non-friends and Remove Friend for existing friends. When
A has sent a friendship request to B, the button becomes "Cancel Friendship
Request". However, it makes no sense for B to see the same button text for
the pending request, since it's not hers to cancel.
This changeset makes it so that B will see "Friendship Requested", and
the button will lead to B's Friend Requests page, so that she can accept
or reject the request using the latter existing UI.
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/5157">#5157</a>
Props terraling</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpfriendsbpfriendsclassesphp">trunk/bp-friends/bp-friends-classes.php</a></li>
<li><a href="#trunkbpfriendsbpfriendstemplatephp">trunk/bp-friends/bp-friends-template.php</a></li>
<li><a href="#trunkteststestcasesfriendsclassbpfriendsfriendshipphp">trunk/tests/testcases/friends/class-bp-friends-friendship.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpfriendsbpfriendsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-classes.php (7373 => 7374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-classes.php 2013-09-04 21:04:23 UTC (rev 7373)
+++ trunk/bp-friends/bp-friends-classes.php 2013-09-07 01:02:33 UTC (rev 7374)
</span><span class="lines">@@ -182,23 +182,41 @@
</span><span class="cx"> return array( 'friends' => $filtered_friend_ids, 'total' => (int) $total_friend_ids );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- public static function check_is_friend( $loggedin_userid, $possible_friend_userid ) {
</del><ins>+ /**
+ * Check friendship status between two users
+ *
+ * Note that 'pending' means that $initiator_userid has sent a friend
+ * request to $possible_friend_userid that has not yet been approved,
+ * while 'awaiting_response' is the other way around ($possible_friend_userid
+ * sent the initial request)
+ *
+ * @param int $initiator_userid The id of the user who is the initiator
+ * of the potential friendship/request.
+ * @param int $possible_friend_userid The id of the user who is the
+ * recipient of the potential friendship/request.
+ * @return string The friendship status, from among 'not_friends',
+ * 'is_friend', 'pending', and 'awaiting_response'
+ */
+ public static function check_is_friend( $initiator_userid, $possible_friend_userid ) {
</ins><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><del>- if ( empty( $loggedin_userid ) || empty( $possible_friend_userid ) )
</del><ins>+ if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $loggedin_userid, $possible_friend_userid, $possible_friend_userid, $loggedin_userid ) );
</del><ins>+ $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, initiator_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $initiator_userid, $possible_friend_userid, $possible_friend_userid, $initiator_userid ) );
</ins><span class="cx">
</span><del>- if ( !empty( $result ) ) {
</del><ins>+ if ( ! empty( $result ) ) {
</ins><span class="cx"> if ( 0 == (int) $result[0]->is_confirmed ) {
</span><del>- return 'pending';
</del><ins>+ $status = $initiator_userid == $result[0]->initiator_user_id ? 'pending' : 'awaiting_response';
</ins><span class="cx"> } else {
</span><del>- return 'is_friend';
</del><ins>+ $status = 'is_friend';
</ins><span class="cx"> }
</span><span class="cx"> } else {
</span><del>- return 'not_friends';
</del><ins>+ $status = 'not_friends';
</ins><span class="cx"> }
</span><ins>+
+ return $status;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> public static function get_bulk_last_active( $user_ids ) {
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendstemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-template.php (7373 => 7374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-template.php 2013-09-04 21:04:23 UTC (rev 7373)
+++ trunk/bp-friends/bp-friends-template.php 2013-09-07 01:02:33 UTC (rev 7374)
</span><span class="lines">@@ -290,6 +290,23 @@
</span><span class="cx"> );
</span><span class="cx"> break;
</span><span class="cx">
</span><ins>+ case 'awaiting_response' :
+ $button = array(
+ 'id' => 'awaiting_response',
+ 'component' => 'friends',
+ 'must_be_logged_in' => true,
+ 'block_self' => true,
+ 'wrapper_class' => 'friendship-button awaiting_response_friend',
+ 'wrapper_id' => 'friendship-button-' . $potential_friend_id,
+ 'link_href' => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
+ 'link_text' => __( 'Friendship Requested', 'buddypress' ),
+ 'link_title' => __( 'Friendship Requested', 'buddypress' ),
+ 'link_id' => 'friend-' . $potential_friend_id,
+ 'link_rel' => 'remove',
+ 'link_class' => 'friendship-button awaiting_response_friend requested'
+ );
+ break;
+
</ins><span class="cx"> case 'is_friend' :
</span><span class="cx"> $button = array(
</span><span class="cx"> 'id' => 'is_friend',
</span></span></pre></div>
<a id="trunkteststestcasesfriendsclassbpfriendsfriendshipphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/friends/class-bp-friends-friendship.php (7373 => 7374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/friends/class-bp-friends-friendship.php 2013-09-04 21:04:23 UTC (rev 7373)
+++ trunk/tests/testcases/friends/class-bp-friends-friendship.php 2013-09-07 01:02:33 UTC (rev 7374)
</span><span class="lines">@@ -77,6 +77,42 @@
</span><span class="cx"> $this->assertEquals( 1, $friends );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * @group check_is_friend
+ */
+ public function test_check_is_friend_not_friends() {
+ $u1 = $this->create_user();
+ $u2 = $this->create_user();
+ $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
+ }
</ins><span class="cx">
</span><ins>+ /**
+ * @group check_is_friend
+ */
+ public function test_check_is_friend_pending() {
+ $u1 = $this->create_user();
+ $u2 = $this->create_user();
+ friends_add_friend( $u1, $u2, false );
+ $this->assertEquals( 'pending', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
+ }
</ins><span class="cx">
</span><ins>+ /**
+ * @group check_is_friend
+ */
+ public function test_check_is_friend_awaiting_response() {
+ $u1 = $this->create_user();
+ $u2 = $this->create_user();
+ friends_add_friend( $u1, $u2, false );
+ $this->assertEquals( 'awaiting_response', BP_Friends_Friendship::check_is_friend( $u2, $u1 ) );
+ }
+
+ /**
+ * @group check_is_friend
+ */
+ public function test_check_is_friend_is_friend() {
+ $u1 = $this->create_user();
+ $u2 = $this->create_user();
+ friends_add_friend( $u1, $u2, true );
+ $this->assertEquals( 'is_friend', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
+ }
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>