Skip to:
Content

BuddyPress.org

Changeset 7374


Ignore:
Timestamp:
09/07/2013 01:02:33 AM (12 years ago)
Author:
boonebgorges
Message:

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 #5157

Props terraling

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends/bp-friends-classes.php

    r7308 r7374  
    183183    }
    184184
    185     public static function check_is_friend( $loggedin_userid, $possible_friend_userid ) {
    186         global $wpdb, $bp;
    187 
    188         if ( empty( $loggedin_userid ) || empty( $possible_friend_userid ) )
    189             return false;
    190 
    191         $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 ) );
    192 
    193         if ( !empty( $result ) ) {
     185    /**
     186     * Check friendship status between two users
     187     *
     188     * Note that 'pending' means that $initiator_userid has sent a friend
     189     * request to $possible_friend_userid that has not yet been approved,
     190     * while 'awaiting_response' is the other way around ($possible_friend_userid
     191     * sent the initial request)
     192     *
     193     * @param int $initiator_userid The id of the user who is the initiator
     194     *   of the potential friendship/request.
     195     * @param int $possible_friend_userid The id of the user who is the
     196     *   recipient of the potential friendship/request.
     197     * @return string The friendship status, from among 'not_friends',
     198     *   'is_friend', 'pending', and 'awaiting_response'
     199     */
     200    public static function check_is_friend( $initiator_userid, $possible_friend_userid ) {
     201        global $wpdb, $bp;
     202
     203        if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) {
     204            return false;
     205        }
     206
     207        $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 ) );
     208
     209        if ( ! empty( $result ) ) {
    194210            if ( 0 == (int) $result[0]->is_confirmed ) {
    195                 return 'pending';
     211                $status = $initiator_userid == $result[0]->initiator_user_id ? 'pending' : 'awaiting_response';
    196212            } else {
    197                 return 'is_friend';
     213                $status = 'is_friend';
    198214            }
    199215        } else {
    200             return 'not_friends';
    201         }
     216            $status = 'not_friends';
     217        }
     218
     219        return $status;
    202220    }
    203221
  • trunk/bp-friends/bp-friends-template.php

    r7228 r7374  
    291291                break;
    292292
     293            case 'awaiting_response' :
     294                $button = array(
     295                    'id'                => 'awaiting_response',
     296                    'component'         => 'friends',
     297                    'must_be_logged_in' => true,
     298                    'block_self'        => true,
     299                    'wrapper_class'     => 'friendship-button awaiting_response_friend',
     300                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
     301                    'link_href'         => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
     302                    'link_text'         => __( 'Friendship Requested', 'buddypress' ),
     303                    'link_title'        => __( 'Friendship Requested', 'buddypress' ),
     304                    'link_id'           => 'friend-' . $potential_friend_id,
     305                    'link_rel'          => 'remove',
     306                    'link_class'        => 'friendship-button awaiting_response_friend requested'
     307                );
     308                break;
     309
    293310            case 'is_friend' :
    294311                $button = array(
  • trunk/tests/testcases/friends/class-bp-friends-friendship.php

    r7039 r7374  
    7878    }
    7979
     80    /**
     81     * @group check_is_friend
     82     */
     83    public function test_check_is_friend_not_friends() {
     84        $u1 = $this->create_user();
     85        $u2 = $this->create_user();
     86        $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
     87    }
    8088
     89    /**
     90     * @group check_is_friend
     91     */
     92    public function test_check_is_friend_pending() {
     93        $u1 = $this->create_user();
     94        $u2 = $this->create_user();
     95        friends_add_friend( $u1, $u2, false );
     96        $this->assertEquals( 'pending', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
     97    }
    8198
     99    /**
     100     * @group check_is_friend
     101     */
     102    public function test_check_is_friend_awaiting_response() {
     103        $u1 = $this->create_user();
     104        $u2 = $this->create_user();
     105        friends_add_friend( $u1, $u2, false );
     106        $this->assertEquals( 'awaiting_response', BP_Friends_Friendship::check_is_friend( $u2, $u1 ) );
     107    }
     108
     109    /**
     110     * @group check_is_friend
     111     */
     112    public function test_check_is_friend_is_friend() {
     113        $u1 = $this->create_user();
     114        $u2 = $this->create_user();
     115        friends_add_friend( $u1, $u2, true );
     116        $this->assertEquals( 'is_friend', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
     117    }
    82118}
Note: See TracChangeset for help on using the changeset viewer.