Skip to:
Content

BuddyPress.org

Changeset 7442


Ignore:
Timestamp:
10/17/2013 07:00:46 PM (6 years ago)
Author:
boonebgorges
Message:

Improve UX flow around overlapping group invites and requests

This changeset introduces a number of improvements to the flow surrounding
invitations and membership requests to private groups:

  • When a user has previously requested membership in a group, add a note to that effect when the user is being invited to the group via the Send Invites interface.
  • When a user has previously requested membership in a group, automatically accept that invitation and add the user to the group when an invitation is sent by an existing group member.
  • When a user has previously been invited to a group, buttons in the group directory and in the group header should read Accept Invitation instead of Request Membership

The end result is a more logical user experience with regard to joining private
groups.

Fixes #5032

Props Mike_Cowobo

Location:
trunk
Files:
7 edited

Legend:

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

    r7441 r7442  
    3232     */
    3333    public $is_member;
     34
     35    /**
     36     * Does the current user have an outstanding invitation to this group?
     37     *
     38     * @since BuddyPress (1.9.0)
     39     * @var bool
     40     */
     41    public $is_invited;
     42
     43    /**
     44     * Does the current user have a pending membership request to this group?
     45     *
     46     * @since BuddyPress (1.9.0)
     47     * @var bool
     48     */
     49    public $is_pending;
    3450
    3551    /**
     
    7389            $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
    7490            $this->is_member          = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id );
     91            $this->is_invited         = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id );
     92            $this->is_pending         = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id );
    7593
    7694            // If this is a private or hidden group, does the current user have access?
     
    828846        $group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
    829847
    830         // Fetch the logged in users status within each group
    831         $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", bp_loggedin_user_id() ) );
     848        // Fetch the logged-in user's status within each group
     849        $user_status = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) );
     850
    832851        for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
    833852            $paged_groups[$i]->is_member = false;
    834853
    835             foreach ( (array) $user_status as $group_id ) {
    836                 if ( $group_id == $paged_groups[$i]->id ) {
    837                     $paged_groups[$i]->is_member = true;
     854            foreach ( (array) $user_status as $group ) {
     855                $is_member = $is_invited = $is_pending = false;
     856                if ( $group->group_id == $paged_groups[ $i ]->id ) {
     857                    // is_confirmed means the user is a member
     858                    if ( $group->is_confirmed ) {
     859                        $is_member = true;
     860
     861                    // invite_sent means the user has been invited
     862                    } else if ( $group->invite_sent ) {
     863                        $is_invited = true;
     864
     865                    // User has sent request, but has not been confirmed
     866                    } else {
     867                        $is_pending = true;
     868                    }
    838869                }
     870
     871                $paged_groups[ $i ]->is_member = $is_member;
     872                $paged_groups[ $i ]->is_invited = $is_invited;
     873                $paged_groups[ $i ]->is_pending = $is_pending;
    839874            }
    840875        }
  • trunk/bp-groups/bp-groups-functions.php

    r7338 r7442  
    655655        return false;
    656656
    657     if ( !groups_is_user_member( $user_id, $group_id ) && !groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) {
     657    // if the user has already requested membership, accept the request
     658    if ( $membership_id = groups_check_for_membership_request( $user_id, $group_id ) ) {
     659        groups_accept_membership_request( $membership_id, $user_id, $group_id );
     660
     661    // Otherwise, create a new invitation
     662    } else if ( ! groups_is_user_member( $user_id, $group_id ) && ! groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) {
    658663        $invite                = new BP_Groups_Member;
    659664        $invite->group_id      = $group_id;
     
    872877    if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) )
    873878        return false;
     879
     880    // Check if the user is already invited - if so, simply accept invite
     881    if ( groups_check_user_has_invite( $requesting_user_id, $group_id ) ) {
     882        groups_accept_invite( $requesting_user_id, $group_id );
     883        return true;
     884    }
    874885
    875886    $requesting_user                = new BP_Groups_Member;
  • trunk/bp-groups/bp-groups-loader.php

    r7347 r7442  
    413413            );
    414414
    415             // If this is a private group, and the user is not a member, show a "Request Membership" nav item.
     415            // If this is a private group, and the user is not a
     416            // member and does not have an outstanding invitation,
     417            // show a "Request Membership" nav item.
    416418            if ( is_user_logged_in() &&
    417                  !bp_current_user_can( 'bp_moderate' ) &&
    418                  !$this->current_group->is_user_member &&
    419                  !groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
    420                  $this->current_group->status == 'private'
     419                 ! bp_current_user_can( 'bp_moderate' ) &&
     420                 ! $this->current_group->is_user_member &&
     421                 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
     422                 $this->current_group->status == 'private' &&
     423                 ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id )
    421424                ) {
     425
    422426                $sub_nav[] = array(
    423427                    'name'               => __( 'Request Membership', 'buddypress' ),
  • trunk/bp-groups/bp-groups-screens.php

    r7440 r7442  
    479479    if ( 'private' != $bp->groups->current_group->status )
    480480        return false;
     481
     482    // If the user is already invited, accept invitation
     483    if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
     484        if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
     485            bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) );
     486        else
     487            bp_core_add_message( __( 'There was an error accepting the group invitation, please try again.', 'buddypress' ), 'error' );
     488        bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
     489    }
    481490
    482491    // If the user has submitted a request, send it.
  • trunk/bp-groups/bp-groups-template.php

    r7439 r7442  
    17811781                case 'private' :
    17821782
    1783                     // Member has not requested membership yet
    1784                     if ( !bp_group_has_requested_membership( $group ) ) {
     1783                    // Member has outstanding invitation -
     1784                    // show an "Accept Invitation" button
     1785                    if ( $group->is_invited ) {
     1786                        $button = array(
     1787                            'id'                => 'accept_invite',
     1788                            'component'         => 'groups',
     1789                            'must_be_logged_in' => true,
     1790                            'block_self'        => false,
     1791                            'wrapper_class'     => 'group-button ' . $group->status,
     1792                            'wrapper_id'        => 'groupbutton-' . $group->id,
     1793                            'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
     1794                            'link_text'         => __( 'Accept Invitation', 'buddypress' ),
     1795                            'link_title'        => __( 'Accept Invitation', 'buddypress' ),
     1796                            'link_class'        => 'group-button accept-invite',
     1797                        );
     1798
     1799                    // Member has requested membership but request is pending -
     1800                    // show a "Request Sent" button
     1801                    } elseif ( $group->is_pending ) {
     1802                        $button = array(
     1803                            'id'                => 'membership_requested',
     1804                            'component'         => 'groups',
     1805                            'must_be_logged_in' => true,
     1806                            'block_self'        => false,
     1807                            'wrapper_class'     => 'group-button pending ' . $group->status,
     1808                            'wrapper_id'        => 'groupbutton-' . $group->id,
     1809                            'link_href'         => bp_get_group_permalink( $group ),
     1810                            'link_text'         => __( 'Request Sent', 'buddypress' ),
     1811                            'link_title'        => __( 'Request Sent', 'buddypress' ),
     1812                            'link_class'        => 'group-button pending membership-requested',
     1813                        );
     1814
     1815                    // Member has not requested membership yet -
     1816                    // show a "Request Membership" button
     1817                    } else {
    17851818                        $button = array(
    17861819                            'id'                => 'request_membership',
     
    17941827                            'link_title'        => __( 'Request Membership', 'buddypress' ),
    17951828                            'link_class'        => 'group-button request-membership',
    1796                         );
    1797 
    1798                     // Member has requested membership already
    1799                     } else {
    1800                         $button = array(
    1801                             'id'                => 'membership_requested',
    1802                             'component'         => 'groups',
    1803                             'must_be_logged_in' => true,
    1804                             'block_self'        => false,
    1805                             'wrapper_class'     => 'group-button pending ' . $group->status,
    1806                             'wrapper_id'        => 'groupbutton-' . $group->id,
    1807                             'link_href'         => bp_get_group_permalink( $group ),
    1808                             'link_text'         => __( 'Request Sent', 'buddypress' ),
    1809                             'link_title'        => __( 'Request Sent', 'buddypress' ),
    1810                             'link_class'        => 'group-button pending membership-requested',
    18111829                        );
    18121830                    }
  • trunk/bp-templates/bp-legacy/buddypress-functions.php

    r7430 r7442  
    907907        return;
    908908
     909    $group_id = (int) $_POST['group_id'];
     910    $friend_id = (int) $_POST['friend_id'];
     911
    909912    if ( 'invite' == $_POST['friend_action'] ) {
    910         if ( ! groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) )
     913        $group = groups_get_group( $group_id );
     914
     915        // Users who have previously requested membership do not need
     916        // another invitation created for them
     917        if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
     918            $user_status = 'is_pending';
     919
     920        // Create the user invitation
     921        } else if ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) {
     922            $user_status = 'is_invited';
     923
     924        // Miscellaneous failure
     925        } else {
    911926            return;
    912 
    913         $user = new BP_Core_User( $_POST['friend_id'] );
     927        }
     928
     929        $user = new BP_Core_User( $friend_id );
    914930
    915931        echo '<li id="uid-' . $user->id . '">';
     
    920936                <a class="button remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a>
    921937              </div>';
     938
     939        if ( 'is_pending' == $user_status ) {
     940            echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress' ), $user->user_link ) . '</p>';
     941        }
     942
    922943        echo '</li>';
    923944        exit;
    924945
    925946    } elseif ( 'uninvite' == $_POST['friend_action'] ) {
    926         if ( ! groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) )
     947        // Users who have previously requested membership should not
     948        // have their requests deleted on the "uninvite" action
     949        if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
    927950            return;
     951        }
     952
     953        // Remove the unsent invitation
     954        if ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
     955            return;
     956        }
    928957
    929958        exit;
     
    10561085
    10571086        } elseif ( 'private' == $group->status ) {
    1058             check_ajax_referer( 'groups_request_membership' );
    1059 
    1060             if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
    1061                 _e( 'Error requesting membership', 'buddypress' );
     1087
     1088            // If the user has already been invited, then this is
     1089            // an Accept Invitation button
     1090            if ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) {
     1091                check_ajax_referer( 'groups_accept_invite' );
     1092
     1093                if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) {
     1094                    _e( 'Error requesting membership', 'buddypress' );
     1095                } else {
     1096                    echo '<a id="group-' . esc_attr( $group->id ) . '" class="leave-group" rel="leave" title="' . __( 'Leave Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
     1097                }
     1098
     1099            // Otherwise, it's a Request Membership button
    10621100            } else {
    1063                 echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>';
     1101                check_ajax_referer( 'groups_request_membership' );
     1102
     1103                if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
     1104                    _e( 'Error requesting membership', 'buddypress' );
     1105                } else {
     1106                    echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>';
     1107                }
    10641108            }
    10651109        }
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r7228 r7442  
    569569        return;
    570570
     571    $group_id = (int) $_POST['group_id'];
     572    $friend_id = (int) $_POST['friend_id'];
     573
    571574    if ( 'invite' == $_POST['friend_action'] ) {
    572         if ( ! groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) )
     575        $group = groups_get_group( $group_id );
     576
     577        // Users who have previously requested membership do not need
     578        // another invitation created for them
     579        if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
     580            $user_status = 'is_pending';
     581
     582        // Create the user invitation
     583        } else if ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) {
     584            $user_status = 'is_invited';
     585
     586        // Miscellaneous failure
     587        } else {
    573588            return;
     589        }
    574590
    575591        $user = new BP_Core_User( $_POST['friend_id'] );
     
    582598                <a class="button remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a>
    583599              </div>';
     600
     601        if ( 'is_pending' == $user_status ) {
     602            echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress' ), $user->user_link ) . '</p>';
     603        }
     604
    584605        echo '</li>';
    585606        exit;
    586607
    587608    } elseif ( 'uninvite' == $_POST['friend_action'] ) {
    588         if ( ! groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) )
     609        // Users who have previously requested membership should not
     610        // have their requests deleted on the "uninvite" action
     611        if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
    589612            return;
     613        }
     614
     615        // Remove the unsent invitation
     616        if ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
     617            return;
     618        }
    590619
    591620        exit;
     
    717746
    718747        } elseif ( 'private' == $group->status ) {
    719             check_ajax_referer( 'groups_request_membership' );
    720 
    721             if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
    722                 _e( 'Error requesting membership', 'buddypress' );
     748
     749            // If the user has already been invited, then this is
     750            // an Accept Invitation button
     751            if ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) {
     752                check_ajax_referer( 'groups_accept_invite' );
     753
     754                if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) {
     755                    _e( 'Error requesting membership', 'buddypress' );
     756                } else {
     757                    echo '<a id="group-' . esc_attr( $group->id ) . '" class="leave-group" rel="leave" title="' . __( 'Leave Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
     758                }
     759
     760            // Otherwise, it's a Request Membership button
    723761            } else {
    724                 echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>';
     762                check_ajax_referer( 'groups_request_membership' );
     763
     764                if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
     765                    _e( 'Error requesting membership', 'buddypress' );
     766                } else {
     767                    echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>';
     768                }
    725769            }
    726770        }
Note: See TracChangeset for help on using the changeset viewer.