Skip to:
Content
Pages
Categories
Search
Top
Bottom

Combining activities for '/user/activity/groups' & '/user/activity/friends'


  • snarkypuppet
    Participant

    @snarkypuppet

    Hey Everyone – I’m running BP v2 and WP v3.9. I’m looking to have my members home screen include all group and friend activities, so they can check out the latest in their chosen BP world.

    I see that ‘/user/activity/groups’ & ‘/user/activity/friends’ are filtering the activity and have what I want. Is it possible to combine these 2 in an activity filter/request or is there another way to do it?

Viewing 25 replies - 1 through 25 (of 28 total)

  • danbp
    Moderator

    @danbp

    @snarkypuppet,

    for simple filtering, you can use the template file and the appropriate conditionnal (bp_has_activities….) for the activity loop

    For more complex filtering it is better to write your own function.
    So yes it can be done.

    For ex like here
    https://buddypress.org/support/topic/filtering-activity-stream/


    snarkypuppet
    Participant

    @snarkypuppet

    Hey @danbp Thanks for the response. I looked into that thread and that led me to this:

    bp_has_activities to accept multi scope

    This is an enhancement marked for future review… 14 months ago :\ – Looks like the only way to do it is to write a new class/function.

    Is there anyone out there that has written something that includes multiple scopes? Is it possible?


    danbp
    Moderator

    @danbp

    Seems not to be possible for the moment. If you read the ticket, Boone says:

    It’s a nice thought, though I’m not sure if it’d be possible to make this work without refactoring the entire activity query class. Moving to Future Release for discussion.

    Feel free to disccuss this on #4988 or try to create a patch.


    snarkypuppet
    Participant

    @snarkypuppet

    Just did a quick test in bp-activity-template.php. This isn’t any kind of solution as i’m editing core files.

    As suggested in another thread I created an additional ‘case’ in bp_has_activities(). This code does not work and is a pretty basic attempt. Note that I only included the case here, there are a few other edits required in the function. This will return posts by friends in groups you belong to.

    The issue seems to be that we want $primary_id OR $user_id below, not BOTH. Does someone have some insight into a way around this? Or can someone confirm that this is in fact the issue?

    case 'groupsfriends':
    
    if ( bp_is_active( 'groups' ) ) {
    
    	$groups = groups_get_user_groups( $user_id );
    	
    	if ( !empty( $groups['groups'] ) ) {
    		$object = $bp->groups->id;
    		$primary_id = implode( ',', (array) $groups['groups'] );
    	}
    	
    	//$user_id = 0;
    
    }
    
    if ( bp_is_active( 'friends' ) )
    	$friends = friends_get_friend_user_ids( $user_id );
    	if ( empty( $friends ) && empty( $groups['groups'] ) )
    		return false;
    	$user_id = implode( ',', (array) $friends );
    	
    break;

    shanebp
    Moderator

    @shanebp

    Awkward, but you could gather all the ids of the members whose activities should be displayed.
    So, bp_loggedin_user_id() + ids of their friends.
    Then pass the ids in an array to the ‘$user_id’ parameter of bp_has_activities.


    snarkypuppet
    Participant

    @snarkypuppet

    Hey @shanebp – thanks for sharing – I think this might only work if you are looking for friends + personal activity.

    I’ve been scouring the forums and wp stack exchange and haven’t found anyone that has got this setup working. I’m seeing a lot of people saying it can be done but no actual code examples or suggestions for how. I do see that personal + friends activity can be combined with the example given on the activity loop page.

    Is there anyone in the buddypress dev community that has, in practice, combined various scopes successfully?


    shanebp
    Moderator

    @shanebp

    I haven’t tried combining scopes.

    You could try my suggestion re user_ids and set scope=false.

    You could try gathering all the user_ids and then use them to gather all the activity ids and then pass them as a csv string to ‘include’ and set scope=false.

    You could test either idea quickly by just using the logged in user id.

    If you try, I’d be interested in hearing about any result.


    snarkypuppet
    Participant

    @snarkypuppet

    @shanebp Whats the thinking behind using the combination of user_ids and include? I want to show all friend and group activity, not just group activity from members that are my friends which is what would happen if you filter with user_ids using the group scope. The trick is that there are members of my groups that are not my friends, and there are friends that are not in my groups. Do I understand you correctly?


    shanebp
    Moderator

    @shanebp

    ‘include’ is for activity ids.
    So you’d gather user_ids and use them to gather activity ids.
    And then only pass in the activity ids via ‘include’.

    In both cases I suggest, scope needs to be ‘false’.

    Examine the function bp_has_activities to get better understanding of the parameter possibilities.


    snarkypuppet
    Participant

    @snarkypuppet

    Oh ok – would that include group activity though?


    shanebp
    Moderator

    @shanebp

    Why wouldn’t it?
    I’m suggesting ways to get around the current limitations of ‘scope’.
    Set scope=false and then try either or both of my untested suggestions.


    snarkypuppet
    Participant

    @snarkypuppet

    Because the groups you belong to are not included, just your friends ID’s. You’ll get some of your friends group activity – It won’t have your own groups in the activity.


    shanebp
    Moderator

    @shanebp

    Did you try it or are you guessing ?

    This works for me:
    if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . '&user_id=1,2&scope=false') )

    logged in user id = 1
    Members 1 & 2 are friends.
    They both belong to groups – but not the same groups.

    The result shows activity for both members, including group activity.

    Again, bp_loggedin_user_id() + ids of their friends.


    snarkypuppet
    Participant

    @snarkypuppet

    Yeah that does work – my bad – thanks for pushing it back on me. Just checked private groups as well and everything seems good. I had given up, glad to have these merged, woo! 🙂


    snarkypuppet
    Participant

    @snarkypuppet

    Oversight on my end again – @shanebp yes, what your saying is true it will show you group activity from you and your friends. Essentially this is just a friends feed, a copy of /activity/friends. However, it doesn’t show activity from your groups that have members which are not your friends, which was my original concern.

    So confusion aside, the issue is still unresolved, seems like there is no way to show group & friend activity combined.

    Has anyone successfully done this? Written a new bp_get_activities? I wouldn’t mind spending the time tearing apart that function if I knew it was possible – so even a nay or yay from someone who has done it would be fantastic.


    shanebp
    Moderator

    @shanebp

    >However, it doesn’t show activity from your groups that have members which are not your friends

    >Again, bp_loggedin_user_id() + ids of their friends.

    Of course, this will only show friends.

    If you want friends & group members, then collect
    bp_loggedin_user_id() + group member ids + friend ids,
    kick out dupes and pass in a csv string of the ids.


    snarkypuppet
    Participant

    @snarkypuppet

    @shanebp – I dont think that’ll work – what your proposing would then include regular updates, comments, and whatever else from the group member id’s. If your not their friend you dont want to see that stuff.

    If you did do it this way you would probably have to write a function to then remove everything but group posts by group member id’s that are not your friends. Super awkward. :\


    shanebp
    Moderator

    @shanebp

    Try using the ‘include’ parameter.

    Gather user_ids for bp_loggedin_user_id() + friend ids.
    Use those ids to get activity ids.

    Then gather activity ids for groups you belong to.

    Kick out dupes and pass them in via ‘include’ with scope=false.

    Awkward?
    Yes, but much less so than ‘remove everything but group posts by group member id’s that are not your friends.’


    snarkypuppet
    Participant

    @snarkypuppet

    If I understand you correctly your saying run bp_has_activities with user_ids as a filter, then for group activities with your personal group ids, then parse all of the activity id’s together to finally run them through a third time with the include argument?

    Would this method have any issue with the default activivty template loader for load-more?


    shanebp
    Moderator

    @shanebp

    No, do not use user_ids as a filter.

    Use ‘include’ as the filter – ONCE – after you gather the activity ids in a separate process.


    snarkypuppet
    Participant

    @snarkypuppet

    Are you using bp_has_activities to get them?


    snarkypuppet
    Participant

    @snarkypuppet

    @shanebp

    Can you confirm?

    Your saying run bp_has_activities(with all my friend and I argument)

    Get the activity ID’s

    run bp_has_activities(with all my groups for the argument)

    Get the activity ID’s

    Combine/parse remove duplicate id’s from first and second and set to include arg

    run bp_had_activities(with the included id’s)


    shanebp
    Moderator

    @shanebp

    No.
    Create the activity ids string in a separate custom process – not bp_has_activities.
    Then pass the string into bp_has_activities via the include parameter.


    snarkypuppet
    Participant

    @snarkypuppet

    Ok great thanks for the clarification – What functions are you using to do that “seperate custom process”?


    shanebp
    Moderator

    @shanebp

    If I was doing this, I would write a custom function(s) to gather the activity ids.
    And that function would most likely contain one or more custom db queries.

    If you are unable to write such queries, you may want to consider hiring a developer.

Viewing 25 replies - 1 through 25 (of 28 total)
  • The topic ‘Combining activities for '/user/activity/groups' & '/user/activity/friends'’ is closed to new replies.
Skip to toolbar