Skip to:
Content

BuddyPress.org

Changeset 12437


Ignore:
Timestamp:
08/12/2019 08:45:04 PM (7 years ago)
Author:
dcavins
Message:

Invitations: Clean up notifications on acceptance.

Clean up stray notifications when an invitation is revoked.

Props imath.

See #6210.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-notifications.php

    r12429 r12437  
    962962}
    963963add_action( 'groups_delete_group', 'bp_groups_delete_group_delete_all_notifications', 10 );
     964
     965/**
     966 * Remove Group invite notification when a user is uninvited.
     967 *
     968 * @since 5.0.0
     969 *
     970 * @param int $group_id ID of the group being uninvited from.
     971 * @param int $user_id  ID of the user being uninvited.
     972 */
     973function bp_groups_uninvite_user_delete_group_invite_notification( $group_id = 0, $user_id = 0 ) {
     974        if ( ! bp_is_active( 'notifications' ) || ! $group_id || ! $user_id ) {
     975                return;
     976        }
     977
     978        bp_notifications_delete_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
     979}
     980add_action( 'groups_uninvite_user', 'bp_groups_uninvite_user_delete_group_invite_notification', 10, 2 );
    964981
    965982/**
  • trunk/tests/phpunit/testcases/groups/notifications.php

    r12433 r12437  
    1717
    1818                $this->requesting_user_id = self::factory()->user->create();
    19                 $this->group = self::factory()->group->create();
     19                $this->group = self::factory()->group->create( array( 'status' =>  'private' ) );
    2020                $this->filter_fired = '';
    2121        }
    … …  
    251251                $this->assertNotEmpty( $u1_notifications );
    252252
    253                 $this->assertTrue( groups_invite_user( array(
    254                         'user_id' => $users[2],
    255                         'group_id' => $this->group,
    256                 ) ) );
     253                groups_accept_membership_request( false, $users[2], $this->group );
    257254
    258255                $u0_notifications = BP_Notifications_Notification::get( $get_args );
    … …  
    262259        }
    263260
     261        public function test_membership_request_notifications_should_be_cleared_when_request_is_accepted_via_invite() {
     262                $users = self::factory()->user->create_many( 3 );
     263
     264                $this->add_user_to_group( $users[0], $this->group, array(
     265                        'is_admin' => 1,
     266                ) );
     267                $this->add_user_to_group( $users[1], $this->group, array(
     268                        'is_admin' => 1,
     269                ) );
     270
     271                groups_send_membership_request( array(
     272                        'user_id' => $users[2],
     273                        'group_id' => $this->group
     274                ) );
     275
     276                // Both admins should get a notification.
     277                $get_args = array(
     278                        'user_id' => $users[0],
     279                        'item_id' => $this->group,
     280                        'secondary_item_id' => $users[2],
     281                        'component_action' => 'new_membership_request',
     282                        'is_new' => true,
     283                );
     284                $u0_notifications = BP_Notifications_Notification::get( $get_args );
     285                $u1_notifications = BP_Notifications_Notification::get( $get_args );
     286                $this->assertNotEmpty( $u0_notifications );
     287                $this->assertNotEmpty( $u1_notifications );
     288
     289                // 'Accept' the request by sending an invite.
     290                groups_invite_user( array(
     291                        'user_id' => $users[2],
     292                        'group_id' => $this->group,
     293                        'send_invite' => true
     294                ) );
     295
     296                $u0_notifications = BP_Notifications_Notification::get( $get_args );
     297                $u1_notifications = BP_Notifications_Notification::get( $get_args );
     298                $this->assertEmpty( $u0_notifications );
     299                $this->assertEmpty( $u1_notifications );
     300        }
     301
    264302}
Note: See TracChangeset for help on using the changeset viewer.