Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/25/2022 07:33:13 PM (4 years ago)
Author:
imath
Message:

Improve the activity loop to be able to get items below a max. ID

The $filter parameter of this loop now includes a new $offset_lower
argument making it possible to only retrieve activities having an ID
lower than this argument provided value.

We are using this filter to avoid a possible activity duplicate when
clicking on the "Load More" link.

Closes https://github.com/buddypress/buddypress/pull/29
Fixes #4535

File:
1 edited

Legend:

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

    r13326 r13344  
    273273                        'secondary_id'      => false,        // Secondary object ID to filter on e.g. a post_id.
    274274                        'offset'            => false,        // Return only items >= this ID.
     275                        'offset_lower'      => false,        // Return only items < this ID.
    275276                        'since'             => false,        // Return only items recorded since this Y-m-d H:i:s date.
    276277
     
    327328                        'object' => $_GET['afilter']
    328329                );
    329         } elseif ( ! empty( $r['user_id'] ) || ! empty( $r['object'] ) || ! empty( $r['action'] ) || ! empty( $r['primary_id'] ) || ! empty( $r['secondary_id'] ) || ! empty( $r['offset'] ) || ! empty( $r['since'] ) ) {
     330        } elseif ( ! empty( $r['user_id'] ) || ! empty( $r['object'] ) || ! empty( $r['action'] ) || ! empty( $r['primary_id'] ) || ! empty( $r['secondary_id'] ) || ! empty( $r['offset'] ) || ! empty( $r['offset_lower'] ) || ! empty( $r['since'] ) ) {
    330331                $r['filter'] = array(
    331332                        'user_id'      => $r['user_id'],
     
    335336                        'secondary_id' => $r['secondary_id'],
    336337                        'offset'       => $r['offset'],
     338                        'offset_lower' => $r['offset_lower'],
    337339                        'since'        => $r['since']
    338340                );
     
    411413                global $activities_template;
    412414
    413                 $url  = bp_get_requested_url();
    414                 $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url );
     415                $url            = bp_get_requested_url();
     416                $load_more_args = array(
     417                        $activities_template->pag_arg => $activities_template->pag_page + 1,
     418                );
     419
     420                // Try to include the offset arg.
     421                $last_displayed_activity = reset( $activities_template->activities );
     422                if ( isset( $last_displayed_activity->id ) && $last_displayed_activity->id ) {
     423                        $load_more_args['offset_lower'] = (int) $last_displayed_activity->id;
     424                }
     425
     426                $link = add_query_arg( $load_more_args, $url );
    415427
    416428                /**
Note: See TracChangeset for help on using the changeset viewer.