<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][13344] trunk/src: Improve the activity loop to be able to get items below a max.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13344">13344</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13344","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-10-25 19:33:13 +0000 (Tue, 25 Oct 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="http://buddypress.trac.wordpress.org/ticket/4535">#4535</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivitytemplatephp">trunk/src/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunksrcbpactivityclassesclassbpactivityactivityphp">trunk/src/bp-activity/classes/class-bp-activity-activity.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressfunctionsphp">trunk/src/bp-templates/bp-legacy/buddypress-functions.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacyjsbuddypressjs">trunk/src/bp-templates/bp-legacy/js/buddypress.js</a></li>
<li><a href="#trunksrcbptemplatesbpnouveauincludesfunctionsphp">trunk/src/bp-templates/bp-nouveau/includes/functions.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaujsbuddypressactivityjs">trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-template.php 2022-10-23 02:21:19 UTC (rev 13343)
+++ trunk/src/bp-activity/bp-activity-template.php 2022-10-25 19:33:13 UTC (rev 13344)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,6 +272,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'primary_id' => $primary_id, // Object ID to filter on e.g. a group_id or blog_id etc.
</span><span class="cx" style="display: block; padding: 0 10px"> 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id.
</span><span class="cx" style="display: block; padding: 0 10px"> 'offset' => false, // Return only items >= this ID.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'offset_lower' => false, // Return only items < this ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> 'since' => false, // Return only items recorded since this Y-m-d H:i:s date.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => false, // Filter on activity meta. See WP_Meta_Query for format.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -326,7 +327,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $r['filter'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'object' => $_GET['afilter']
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } 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'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } 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'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $r['filter'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'user_id' => $r['user_id'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'object' => $r['object'],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -334,6 +335,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'primary_id' => $r['primary_id'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'secondary_id' => $r['secondary_id'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'offset' => $r['offset'],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'offset_lower' => $r['offset_lower'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'since' => $r['since']
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -410,9 +412,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_get_activity_load_more_link() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $activities_template;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $url = bp_get_requested_url();
- $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $url = bp_get_requested_url();
+ $load_more_args = array(
+ $activities_template->pag_arg => $activities_template->pag_page + 1,
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Try to include the offset arg.
+ $last_displayed_activity = reset( $activities_template->activities );
+ if ( isset( $last_displayed_activity->id ) && $last_displayed_activity->id ) {
+ $load_more_args['offset_lower'] = (int) $last_displayed_activity->id;
+ }
+
+ $link = add_query_arg( $load_more_args, $url );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the Load More link URL.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcbpactivityclassesclassbpactivityactivityphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/classes/class-bp-activity-activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/classes/class-bp-activity-activity.php 2022-10-23 02:21:19 UTC (rev 13343)
+++ trunk/src/bp-activity/classes/class-bp-activity-activity.php 2022-10-25 19:33:13 UTC (rev 13344)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1922,6 +1922,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * 'secondary_item_id' column in the database.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $offset Return only those items with an ID greater
</span><span class="cx" style="display: block; padding: 0 10px"> * than the offset value.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type int $offset_lower Return only those items with an ID lower
+ * than the offset value.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string $since Return only those items that have a
</span><span class="cx" style="display: block; padding: 0 10px"> * date_recorded value greater than a
</span><span class="cx" style="display: block; padding: 0 10px"> * given MySQL-formatted date.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1967,6 +1969,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $filter_sql[] = "a.id >= {$sid_sql}";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $filter_array['offset_lower'] ) ) {
+ $sid_sql = absint( $filter_array['offset_lower'] );
+ $filter_sql[] = "a.id < {$sid_sql}";
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $filter_array['since'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Validate that this is a proper Y-m-d H:i:s date.
</span><span class="cx" style="display: block; padding: 0 10px"> // Trick: parse to UNIX date then translate back.
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/buddypress-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress-functions.php 2022-10-23 02:21:19 UTC (rev 13343)
+++ trunk/src/bp-templates/bp-legacy/buddypress-functions.php 2022-10-25 19:33:13 UTC (rev 13344)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -765,6 +765,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $qs[] = 'offset=' . intval( $_POST['offset'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $_POST['offset_lower'] ) ) {
+ $qs[] = 'offset_lower=' . intval( $_POST['offset_lower'] );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $object_search_text = bp_get_search_default_text( $object );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $_POST['search_terms'] ) && is_string( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
</span><span class="cx" style="display: block; padding: 0 10px"> $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacyjsbuddypressjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/js/buddypress.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/js/buddypress.js 2022-10-23 02:21:19 UTC (rev 13343)
+++ trunk/src/bp-templates/bp-legacy/js/buddypress.js 2022-10-25 19:33:13 UTC (rev 13344)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -431,6 +431,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /* Load more updates at the end of the page */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( target.parent().hasClass('load-more') ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var loadMoreLink = new URL( jq( target ).prop( 'href' ) ),
+ offsetLower = parseInt( loadMoreLink.searchParams.get( 'offset_lower' ), 10 ) || 0;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( bp_ajax_request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> bp_ajax_request.abort();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -448,6 +451,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> action: 'activity_get_older_updates',
</span><span class="cx" style="display: block; padding: 0 10px"> 'cookie': bp_get_cookies(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'page': oldest_page,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'offset_lower': offsetLower,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'exclude_just_posted': just_posted.join(',')
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveauincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/includes/functions.php 2022-10-23 02:21:19 UTC (rev 13343)
+++ trunk/src/bp-templates/bp-nouveau/includes/functions.php 2022-10-25 19:33:13 UTC (rev 13344)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -117,6 +117,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $qs[] = 'offset=' . intval( $post_query['offset'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $post_query['offset_lower'] ) ) {
+ $qs[] = 'offset_lower=' . intval( $post_query['offset_lower'] );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $object_search_text = bp_get_search_default_text( $object );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $post_query['search_terms'] ) && $object_search_text != $post_query['search_terms'] && 'false' != $post_query['search_terms'] && 'undefined' != $post_query['search_terms'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveaujsbuddypressactivityjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js 2022-10-23 02:21:19 UTC (rev 13343)
+++ trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js 2022-10-25 19:33:13 UTC (rev 13344)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -273,12 +273,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Load more activities
</span><span class="cx" style="display: block; padding: 0 10px"> } else if ( $( event.currentTarget ).hasClass( 'load-more' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var next_page = ( Number( this.current_page ) * 1 ) + 1, self = this, search_terms = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var next_page = ( Number( this.current_page ) * 1 ) + 1, self = this, search_terms = '',
+ loadMoreLink = $( event.currentTarget ).children().first(),
+ offsetLower = loadMoreLink ? bp.Nouveau.getLinkParams( loadMoreLink.prop( 'href' ), 'offset_lower' ) : 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Stop event propagation
</span><span class="cx" style="display: block; padding: 0 10px"> event.preventDefault();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $( event.currentTarget ).find( 'a' ).first().addClass( 'loading' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ loadMoreLink.addClass( 'loading' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // reset the just posted
</span><span class="cx" style="display: block; padding: 0 10px"> this.just_posted = [];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -300,6 +302,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> page : next_page,
</span><span class="cx" style="display: block; padding: 0 10px"> method : 'append',
</span><span class="cx" style="display: block; padding: 0 10px"> exclude_just_posted : this.just_posted.join( ',' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ offset_lower : offsetLower,
</ins><span class="cx" style="display: block; padding: 0 10px"> target : '#buddypress [data-bp-list] ul.bp-list'
</span><span class="cx" style="display: block; padding: 0 10px"> } ).done( function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( true === response.success ) {
</span></span></pre>
</div>
</div>
</body>
</html>