Skip to:
Content

BuddyPress.org

Changeset 9958


Ignore:
Timestamp:
06/21/2015 11:07:19 AM (9 years ago)
Author:
imath
Message:

Blogs: make sure filtering activities by the new_blog_comment action gets the corresponding entries on the just-me scope and that these entries are ordered DESC by date.

When activity comments are synced with blog post comments, and when the activity filter is set to new_blog_comment :

  • while browsing the activities in the profile of a user, no activities were fetched.
  • while browsing the activity directory, the heartbeat feature kept on generating the "Load newest" link although no new activities were posted.

Using a specific BP_Activity_Query is fixing both issues.

Fixes #6485

File:
1 edited

Legend:

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

    r9822 r9958  
    767767 */
    768768function bp_blogs_new_blog_comment_query_backpat( $args ) {
     769    global $wpdb;
     770    $bp = buddypress();
     771
    769772    // Bail if this is not a 'new_blog_comment' query
    770773    if ( 'new_blog_comment' !== $args['action'] ) {
     
    772775    }
    773776
    774     // display_comments=stream is required to show new-style
    775     // 'activity_comment' items inline
     777    // Comment synced ?
     778    $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = %s", 'bp_blogs_post_comment_id' ) );
     779
     780    if ( empty( $activity_ids ) ) {
     781        return $args;
     782    }
     783
     784    // Init the filter query
     785    $filter_query = array();
     786
     787    if ( 'null' === $args['scope'] ) {
     788        $args['scope'] = '';
     789    } elseif ( 'just-me' === $args['scope'] ) {
     790        $filter_query = array(
     791            'relation' => 'AND',
     792            array(
     793                'column' => 'user_id',
     794                'value'  => bp_displayed_user_id(),
     795            ),
     796        );
     797        $args['scope'] = '';
     798    }
     799
     800    $filter_query[] = array(
     801        'relation' => 'OR',
     802        array(
     803            'column' => 'type',
     804            'value'  => $args['action'],
     805        ),
     806        array(
     807            'column'  => 'id',
     808            'value'   =>  $activity_ids,
     809            'compare' => 'IN'
     810        ),
     811    );
     812
     813    $args['filter_query'] = $filter_query;
     814
     815    // Make sure to have comment in stream mode && avoid duplicate content
    776816    $args['display_comments'] = 'stream';
    777817
    778     // For the remaining clauses, we filter the SQL query directly
    779     add_filter( 'bp_activity_paged_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' );
    780     add_filter( 'bp_activity_total_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' );
     818    // Finally reset the action
     819    $args['action'] = '';
    781820
    782821    // Return the original arguments
     
    784823}
    785824add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' );
    786 
    787 /**
    788  * Filter activity SQL to include new- and old-style 'new_blog_comment' activity items.
    789  *
    790  * @since BuddyPress (2.1.0)
    791  *
    792  * @access private
    793  * @see bp_blogs_new_blog_comment_query_backpat()
    794  *
    795  * @param string $query SQL query as assembled in BP_Activity_Activity::get().
    796  * @return string $query Modified SQL query.
    797  */
    798 function _bp_blogs_new_blog_comment_query_backpat_filter( $query ) {
    799     $bp = buddypress();
    800 
    801     // The query passed to the filter is for old-style 'new_blog_comment'
    802     // items. We include new-style 'activity_comment' items by running a
    803     // subquery inside of a large OR clause.
    804     $activity_comment_subquery = "SELECT a.id FROM {$bp->activity->table_name} a INNER JOIN {$bp->activity->table_name_meta} am ON (a.id = am.activity_id) WHERE am.meta_key = 'bp_blogs_post_comment_id' AND a.type = 'activity_comment'";
    805 
    806     // WHERE ( [original WHERE clauses] OR a.id IN (activity_comment subquery) )
    807     $query = preg_replace( '|WHERE (.*?) ORDER|', 'WHERE ( ( $1 ) OR ( a.id IN ( ' . $activity_comment_subquery . ' ) ) ) ORDER', $query );
    808 
    809     // Don't run this on future queries
    810     remove_filter( current_filter(), '_bp_blogs_new_blog_comment_query_backpat_filter' );
    811 
    812     return $query;
    813 }
    814825
    815826/**
Note: See TracChangeset for help on using the changeset viewer.