Skip to:
Content
Pages
Categories
Search
Top
Bottom

A new activities stream

  • @homework17

    Member

    People, I’m trying to build a stream with friends only and user activities. Reading the documentation for bp_has_activities(), I tried a couple of parameters like ‘scope=just-me&scope=friends’… It didn’t worked, so someone has a better idea?

Viewing 7 replies - 1 through 7 (of 7 total)
  • @candy2012

    Member

    did you manage to find a solution to this? I am desperately looking for smth similar and did not find any solution through these forums.

    scope=just-me&scope=friends will not work as that bp_has_activities only accepts ONE parameter (so only scope=just-me for ex). I have been there too, tried all possible combinations than read somewhere that it will simply not work that way.

    If you solved it I’d so much appreciate a hint as of how you did it.
    Thanks

    @modemlooper

    Moderator

    You have to create a function similar to what I’m using below. Play with the if statement after the for each loop.

    `
    function bp_my_activity_filter( $a, $activities ) {
    global $bp;

    if ( $bp->current_component != $bp->activity->slug )
    return $activities;

    foreach( $activities->activities as $key => $activity ) {
    if ( $activity->type ==’activity_update’ && $activity->item_id == ’34’ || $activity->type ==’new_forum_topic’ && $activity->item_id == ’34’ ) {
    unset( $activities->activities[$key] );
    $activities->total_activity_count = $activities->total_activity_count – 1;
    $activities->activity_count = $activities->activity_count – 1;
    }
    }

    $activities_new = array_values( $activities->activities );
    $activities->activities = $activities_new;
    return $activities;
    }
    add_action( ‘bp_has_activities’, ‘bp_my_activity_filter’, 10, 2 );
    `

    @candy2012

    Member

    Thank you @modemlooper !

    I don’t think I really know how to start on that …

    I have tried this:

    foreach( $activities->activities as $key => $activity ) {
    if ( $activity->scope ==’friends’ || $activity->scope ==’just_me’) {
    unset( $activities->activities[$key] );

    but it does not work, I mean I only get the friends but not my own posts :-(

    As far as I understood is the “scope” I need not the action types (I want all actions to show, but for friends and the current user only)

    What am I doing wrong?

    An other thing that I have noticed, when I click on the “All users” Tab, the site-wide activity is there all untouched, and this is definitely not supposed to hapen. I need to filter that fully out!

    Just like Facebook! Imagine you loginto Facebook and get the billions of user activity statuses rolling in front of your eyes …

    I guess it has to be checked somehow that the displayed activity belongs to the current-user friends only …
    but how !??!

    @modemlooper

    Moderator

    Change || to &&

    @candy2012

    Member

    Thank you @modemlooper but that’s not enough and makes no change; we need a function to check if friend or not to apply to all streams.

    And I think I can say …. yes yes yes yes yes! I found the combination that seems to finally turn buddypress into a modern social network :-)

    So here the wonder-code (it must have smth to do with 11/11/11 > wish came true :) ):

    Code:
    function my_is_friend_check( $friend_id = false) {
    global $bp;

    if ( !is_user_logged_in() )
    return false;

    if ( is_site_admin() )
    return true;

    if ( !$friend_id ) {
    $potential_friend_id = $bp->displayed_user->id;
    } else {
    $potential_friend_id = $friend_id;
    }

    if ( $bp->loggedin_user->id == $potential_friend_id )
    return false;

    if ( friends_check_friendship_status($bp->loggedin_user->id, $potential_friend_id) == ‘is_friend’ )
    return true;

    return false;
    }

    function my_denied_activity_nonfriends( $a, $activities ) {
    global $bp;

    //if admin we want to know
    if ( is_site_admin() )
    return $activities;

    foreach ( $activities->activities as $key => $activity ) {

    if ( $activity->user_id != $bp->loggedin_user->id && $activity->user_id != 0 && !my_is_friend_check($activity->user_id) ) {

    unset( $activities->activities[$key] );

    $activities->activity_count = $activities->activity_count-1;
    $activities->total_activity_count = $activities->total_activity_count-1;
    $activities->pag_num = $activities->pag_num -1;

    }
    }

    $activities_new = array_values( $activities->activities );
    $activities->activities = $activities_new;

    return $activities;
    }
    add_action( ‘bp_has_activities’, ‘my_denied_activity_nonfriends’, 10, 2 );

    For all buddymuppets to enjoy :-)

    @modemlooper

    Moderator

    I don’t think you need that first function when bp already has a friend filter but good job figuring something out

    @candy2012

    Member

    the reason you need the 1st part is that if you do not do it, when you click the Tab “All Members” you will still be served the unfiltered all users activity stream. that’s the behaviour that I have witnessed on my site at least.

    So it seems that the first function is blocking everything that is not “me or friend” to be shown.
    And this is what I wanted, this is how the other networks also work.

    Works beautifully now

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘A new activities stream’ is closed to new replies.
Skip to toolbar