### Eclipse Workspace Patch 1.0
#P BuddyPress-trunk
Index: bp-friends/bp-friends-classes.php
===================================================================
--- bp-friends/bp-friends-classes.php	(revision 5892)
+++ bp-friends/bp-friends-classes.php	(working copy)
@@ -207,6 +207,12 @@
 	 	return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) );
 	}
 
+	public static function withdraw($friendship_id) {
+		global $wpdb, $bp;
+
+		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
+	}
+
 	public static function reject($friendship_id) {
 		global $wpdb, $bp;
 
Index: bp-friends/bp-friends-functions.php
===================================================================
--- bp-friends/bp-friends-functions.php	(revision 5892)
+++ bp-friends/bp-friends-functions.php	(working copy)
@@ -139,6 +139,23 @@
 	return false;
 }
 
+function friends_withdraw_friendship( $initiator_userid, $friend_userid ) {
+	global $bp;
+
+	$friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
+	$friendship = new BP_Friends_Friendship( $friendship_id, true, false );
+	
+	if ( !$friendship->is_confirmed && BP_Friends_Friendship::withdraw( $friendship_id ) ) {
+		// Remove the friend request notice
+		bp_core_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
+
+		do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
+		return true;
+	}
+
+	return false;
+}
+
 function friends_check_friendship( $user_id, $possible_friend_id ) {
 
 	if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
Index: bp-themes/bp-default/_inc/ajax.php
===================================================================
--- bp-themes/bp-default/_inc/ajax.php	(revision 5892)
+++ bp-themes/bp-default/_inc/ajax.php	(working copy)
@@ -477,8 +477,17 @@
 		if ( !friends_add_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
 			echo __("Friendship could not be requested.", 'buddypress');
 		} else {
-			echo '<a href="' . bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests" class="requested">' . __( 'Friendship Requested', 'buddypress' ) . '</a>';
+			echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __( 'Cancel Friendship Request', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int)$_POST['fid'] . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
 		}
+	} else if( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
+		
+		check_ajax_referer('friends_withdraw_friendship');
+		
+		if ( friends_withdraw_friendship( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
+			echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __( 'Add Friend', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
+		} else {
+			echo __("Friendship request could not be cancelled.", 'buddypress');
+		}
 	} else {
 		echo __( 'Request Pending', 'buddypress' );
 	}
Index: bp-themes/bp-default/_inc/global.js
===================================================================
--- bp-themes/bp-default/_inc/global.js	(revision 5892)
+++ bp-themes/bp-default/_inc/global.js	(working copy)
@@ -917,7 +917,7 @@
 					function() {
 						parentdiv.removeClass('add_friend');
 						parentdiv.removeClass('loading');
-						parentdiv.addClass('pending');
+						parentdiv.addClass('pending_friend');
 						parentdiv.fadeIn(200).html(response);
 					}
 					);
Index: bp-friends/bp-friends-screens.php
===================================================================
--- bp-friends/bp-friends-screens.php	(revision 5892)
+++ bp-friends/bp-friends-screens.php	(working copy)
@@ -47,6 +47,17 @@
 			bp_core_add_message( __( 'Friendship could not be rejected', 'buddypress' ), 'error' );
 
 		bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
+		
+	} elseif ( bp_is_action_variable( 'cancel', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
+		// Check the nonce
+		check_admin_referer( 'friends_withdraw_friendship' );
+
+		if ( friends_withdraw_friendship( bp_loggedin_user_id(), bp_action_variable( 1 ) ) )
+			bp_core_add_message( __( 'Friendship request withdrawn', 'buddypress' ) );
+		else
+			bp_core_add_message( __( 'Friendship request could not be withdrawn', 'buddypress' ), 'error' );
+
+		bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
 	}
 
 	do_action( 'friends_screen_requests' );
Index: bp-friends/bp-friends-template.php
===================================================================
--- bp-friends/bp-friends-template.php	(revision 5892)
+++ bp-friends/bp-friends-template.php	(working copy)
@@ -318,12 +318,14 @@
 					'component'         => 'friends',
 					'must_be_logged_in' => true,
 					'block_self'        => true,
-					'wrapper_class'     => 'friendship-button pending',
+					'wrapper_class'     => 'friendship-button pending_friend',
 					'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
-					'link_href'         => trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests' ),
-					'link_text'         => __( 'Friendship Requested', 'buddypress' ),
-					'link_title'        => __( 'Friendship Requested', 'buddypress' ),
-					'link_class'        => 'friendship-button pending requested'
+					'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
+					'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
+					'link_title'        => __( 'Cancel Friendship Requested', 'buddypress' ),
+					'link_id'			=> 'friend-' . $potential_friend_id,
+					'link_rel'			=> 'remove',
+					'link_class'        => 'friendship-button pending_friend requested'
 				);
 				break;
 
