Skip to:
Content

BuddyPress.org


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.