Skip to:
Content

BuddyPress.org


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.