Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2015 08:56:45 AM (10 years ago)
Author:
imath
Message:

Only create a single activity when a friendship is created and make sure to display it on each involved user personal activities.

When a friendship is created, a single public activity will be created. Thanks to the new BP_Activity_Query class introduced in version 2.2, we are able to fetch this activity on each involved user personal activity stream.
Once BuddyPress will be updated to 2.2, all hide_sitewide activities related to a created friendship will be removed as they are not necessary anymore.

Fixes #6040

props boonebgorges, r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-activity.php

    r9318 r9326  
    272272
    273273/**
     274 * Set up activity arguments for use with the 'just-me' scope.
     275 *
     276 * For details on the syntax, see {@link BP_Activity_Query}.
     277 *
     278 * @since BuddyPress (2.2.0)
     279 *
     280 * @param array $retval Empty array by default
     281 * @param array $filter Current activity arguments
     282 * @return array
     283 */
     284function bp_friends_filter_activity_just_me_scope( $retval, $filter ) {
     285    // Get the requested action
     286    $action = $filter['filter']['action'];
     287
     288    // Make sure actions are listed in an array
     289    if ( ! is_array( $action ) ) {
     290        $action = explode( ',', $filter['filter']['action'] );
     291    }
     292
     293    $action = array_flip( array_filter( $action ) );
     294
     295    /**
     296     * If filtering activities for something other than the friendship_created action
     297     * return without changing anything
     298     */
     299    if ( ! empty( $action ) && ! isset( $action['friendship_created'] ) ) {
     300        return $retval;
     301    }
     302
     303    /**
     304     * Else make sure to get the friendship_created action, the user is involved in
     305     * - user initiated the friendship
     306     * - user has been requested a friendship
     307     */
     308    return array(
     309        'relation' => 'OR',
     310        array(
     311            'column' => 'user_id',
     312            'value'  => $filter['user_id']
     313        ),
     314        array(
     315            'relation' => 'AND',
     316            array(
     317                'column' => 'component',
     318                'value'  => 'friends',
     319            ),
     320            array(
     321                'column' => 'secondary_item_id',
     322                'value'  => $filter['user_id'],
     323            ),
     324        ),
     325        'override' => array(
     326            'display_comments' => 'stream',
     327            'filter'           => array( 'user_id' => 0 ),
     328        ),
     329    );
     330}
     331add_filter( 'bp_activity_set_just-me_scope_args', 'bp_friends_filter_activity_just_me_scope', 20, 2 );
     332
     333/**
    274334 * Add activity stream items when one members accepts another members request
    275335 * for virtual friendship.
     
    294354        'secondary_item_id' => $friend_user_id
    295355    ) );
    296 
    297     // Record in activity streams for the friend
    298     friends_record_activity( array(
    299         'user_id'           => $friend_user_id,
    300         'type'              => 'friendship_created',
    301         'item_id'           => $friendship_id,
    302         'secondary_item_id' => $initiator_user_id,
    303         'hide_sitewide'     => true // We've already got the first entry site wide
    304     ) );
    305356}
    306357add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 );
Note: See TracChangeset for help on using the changeset viewer.