Skip to:
Content
Pages
Categories
Search
Top
Bottom

@mentions show up on personal activity streams like they do here on BP.org?


  • bplove
    Participant

    @bplove

    Is there a setting or an easy hack to get @mentions to show up on personal activity like they do here on bp.org? It doesn’t happen this way on my install, just shows the user activity and you have to click @mentions to see their @mentions. I like it better together. Tips?

Viewing 11 replies - 1 through 11 (of 11 total)

  • Marc R.
    Participant

    @marcrem

    @bplove please share if you find a way to do it, I’m looking forward to do it too


    Roger Coathup
    Participant

    @rogercoathup

    @bplove @marcrem

    You’ll need to build your own bespoke theme, with a custom activity loop that doesn’t filter ‘the scope’, but instead shows all activities.

    Sounds confusing – unfortunately, it is a little.

    The default BuddyPress theme uses a set of filters (put together by a javascript routine in _inc/ajax.php) to determine which entries to show when you visit someone’s activity.

    You can read more about building your own theme, and on writing a custom activity loop in the docs section of this site.


    Matt Cox
    Participant

    @mattamatic

    For the benefit of anyone else attempting to implement this, the above post is incorrect. Buddypress implemented @mention listing by searching the text of all activity updates. The function to query for activity (BP_Activity_Activity:get) allows you to query by user id AND search term, but not user id OR search term, as this feature requires.

    The only way I was able to get this working was by hacking bp-activity-classes.php, and updating the user_id sql in the get_filter_sql function. The updated code is as follows:

    `if ( !empty( $filter_array ) ) {
    $user_filter = explode( ‘,’, $filter_array );
    $user_sql = ” ( a.user_id IN ( ” . $filter_array . ” ) “;
    foreach ( $user_filter as $user_id ) {
    $search_terms = ‘@’ . bp_core_get_username( $user_id ) . ‘<';
    $user_sql .= “OR ( a.content LIKE ‘%%”.like_escape($search_terms).”%%’ ) “;
    }
    $user_sql .= ” ) “;
    $filter_sql[] = $user_sql;
    }`

    If someone has a more elegant solution, please let me know!


    Boone Gorges
    Keymaster

    @boonebgorges

    Here’s how buddypress.org does it, with a filter that essentially adds a search term ‘ @username‘ to the bp_has_activities filter:
    `function bporg_activity_with_others_filter( $qs ) {
    global $bp;

    $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();

    /* Only filter on directory pages (no action) and the following scope on activity object. */
    if ( ( ‘dashboard’ == $bp->current_action && strpos( $qs, ‘personal’ ) !== false ) || ‘just-me’ == $bp->current_action ) {
    if ( strpos( $qs, ‘filter’ ) === false )
    $qs .= ‘&search_terms=@’ . bp_core_get_username( $user_id ) . ‘<';

    return $qs;
    } else {
    return $qs;
    }
    }
    add_filter( ‘bp_ajax_querystring’, ‘bporg_activity_with_others_filter’, 11 );`

    The problem with this approach is that the search bypasses the private/hidden group setting, so activity created inside of a group will show up on public profile pages if it contains @username in it. Here’s a filter that gets around it about halfway, in a hackish way:
    `function bporg_ensure_hidden_activity_updates( $has_activities ) {
    global $activities_template, $bp;

    if ( bp_is_my_profile() || !$bp->displayed_user->id )
    return $has_activities;

    foreach( $activities_template->activities as $a_key => $a ) {
    if ( $a->type != ‘activity_update’ && $a->type != ‘activity_comment’ )
    continue;

    if ( $a->component != ‘groups’ )
    continue;

    $group = new BP_Groups_Group( $a->item_id );

    if ( $group->status != ‘public’ ) {
    unset( $activities_template->activities[$a_key] );
    $activities_template->total_activity_count = $activities_template->total_activity_count – 1;
    $activities_template->activity_count = $activities_template->activity_count – 1;
    }

    $activities_template->activities = array_values( $activities_template->activities );
    }

    return $has_activities;
    }
    add_filter( ‘bp_has_activities’, ‘bporg_ensure_hidden_activity_updates’, 999 );`

    This latter problem should be fixed in BP 1.3.


    luvs
    Member

    @luvs123

    does not work for me boone

    @mattamatic you rock man, your code worked perfect for me here (something i’m doing for a client)… http://www.deconstruct3d.com/aampp. THANKS!


    KZeni
    Participant

    @kzeni

    Not sure if anyone else still needs the ability to combine @mentions with the personal activity stream. I took the guidance of @mattamatic with an alteration to get it working with BP 1.7 (beta 2, in my case).

    I opened up `buddypress/bp-activity/bp-activity-classes.php`, found `lines 620-624` (part of the get_filter_sql function), and changed it from:

    `if ( !empty( $filter_array[‘user_id’] ) ) {
    $user_sql = BP_Activity_Activity::get_in_operator_sql( ‘a.user_id’, $filter_array[‘user_id’] );
    if ( !empty( $user_sql ) )
    $filter_sql[] = $user_sql;
    }`

    To:

    `if ( !empty( $filter_array[‘user_id’] ) ) {
    $user_sql = BP_Activity_Activity::get_in_operator_sql( ‘a.user_id’, $filter_array[‘user_id’] );
    // START Also include @Mentions in User Stream
    $search_terms = ‘@’.bp_core_get_username($user_id);
    $user_sql.= “OR ( a.content LIKE ‘%%”.like_escape($search_terms).”%%’ )”;
    // END Also include @Mentions in User Stream
    if ( !empty( $user_sql ) )
    $filter_sql[] = $user_sql;
    }`

    Works for me on BuddyPress 1.7-beta2 (wish there was a non-hacked way to combine multiple scopes for the activity stream). Also, I should mention that you really only need to add the parts between the START/END comments, but I included the rest for context.

    Thanks again @mattamatic!


    KZeni
    Participant

    @kzeni

    I can’t edit my post above, but I thought I’d let you know that I’m on BuddyPress 1.7 (non-beta) now and the same edit applies & works on this version as well.


    KZeni
    Participant

    @kzeni

    Turns out there was an issue I didn’t catch until I noticed @mentions were showing up for more than just the specified user. Below is the updated code (really, it’s just a matter of swapping out $user_id for $filter_array[‘user_id’] in the edited code mentioned above). This is working on BuddyPress 1.7.1.

    I opened up buddypress/bp-activity/bp-activity-classes.php, found lines 620-624 (part of the get_filter_sql function), and changed it from:

    if ( !empty( $filter_array['user_id'] ) ) {
    	$user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
    	if ( !empty( $user_sql ) )
    		$filter_sql[] = $user_sql;
    }

    To:

    if ( !empty( $filter_array['user_id'] ) ) {
    	$user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
    	// START Also include @Mentions in User Stream
    	$search_terms = '@'.bp_core_get_username($filter_array['user_id']);
    	$user_sql.= "OR ( a.content LIKE '%%".like_escape($search_terms)."%%' )";
    	// END Also include @Mentions in User Stream
    	if ( !empty( $user_sql ) )
    		$filter_sql[] = $user_sql;
    }

    shanebp
    Moderator

    @shanebp

    @kzeni

    In 1.7, you can adjust the activity query via a filter – so you don’t have to hack a core file.

    Take a look at the bp_activity_get_user_join_filter hook in bp-activity-classes.php
    In particular, the $where_sql


    thisisnousername
    Participant

    @thisisnousername

    thanks @kzeni have been looking this just the solution 🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘@mentions show up on personal activity streams like they do here on BP.org?’ is closed to new replies.
Skip to toolbar