Skip to:
Content

BuddyPress.org

Changeset 12038


Ignore:
Timestamp:
05/02/2018 04:18:33 PM (6 years ago)
Author:
imath
Message:

BP Nouveau: generate the Activity container before adding new entries

If the Activity container is missing, make sure to generate it before prepending new activities. If the container is available the activity will only be inserted if the activity stream can welcome it. For instance, an activity posted in a Private group will be prepended to the list only if the "My Groups" scope is active.

Fixes #7774

Location:
trunk/src/bp-templates/bp-nouveau/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-activity-post-form.js

    r12011 r12038  
    709709
    710710            bp.ajax.post( 'post_update', _.extend( data, this.model.attributes ) ).done( function( response ) {
    711                 var scope     = bp.Nouveau.getStorage( 'bp-activity', 'scope' ),
    712                     prepended = false;
    713 
    714                 if ( ! response.is_directory ||
    715                      ( 'all' === scope && ( 'user' === self.model.get( 'object' ) || false === response.is_private ) ) ||
    716                      ( self.model.get( 'object' ) + 's'  === scope )
    717                     ) {
    718 
    719                     if ( ! $( '#activity-' + response.id  ).length ) {
    720                         bp.Nouveau.inject( '#activity-stream ul.activity-list', response.activity, 'prepend' );
    721                         prepended = true;
    722                     }
     711                var store       = bp.Nouveau.getStorage( 'bp-activity' ),
     712                    searchTerms = $( '[data-bp-search="activity"] input[type="search"]' ).val(), matches = {},
     713                    toPrepend = false;
     714
     715                // Look for matches if the stream displays search results.
     716                if ( searchTerms ) {
     717                    searchTerms = new RegExp( searchTerms, 'im' );
     718                    matches = response.activity.match( searchTerms );
     719                }
     720
     721                /**
     722                 * Before injecting the activity into the stream, we need to check the filter
     723                 * and search terms are consistent with it when posting from a single item or
     724                 * from the Activity directory.
     725                 */
     726                if ( ( ! searchTerms || matches ) ) {
     727                    toPrepend = ! store.filter || 0 === parseInt( store.filter, 10 ) || 'activity_update' === store.filter;
     728                }
     729
     730                /**
     731                 * In the Activity directory, we also need to check the active scope.
     732                 * eg: An update posted in a private group should only show when the
     733                 * "My Groups" tab is active.
     734                 */
     735                if ( toPrepend && response.is_directory ) {
     736                    toPrepend = ( 'all' === store.scope && ( 'user' === self.model.get( 'object' ) || false === response.is_private ) ) || ( self.model.get( 'object' ) + 's'  === store.scope );
    723737                }
    724738
     
    726740                self.resetForm();
    727741
    728                 // Stop here if the activity has been added to the stream
    729                 if ( prepended ) {
    730                     return;
    731                 }
    732 
    733                 /**
    734                  * Do not add to the stream if the scope is not consistent with the activity
    735                  */
    736                 self.views.add( new bp.Views.activityFeedback( { value: response.message, type: 'updated' } ) );
     742                // Display a successful feedback if the acticity is not consistent with the displayed stream.
     743                if ( ! toPrepend ) {
     744                    self.views.add( new bp.Views.activityFeedback( { value: response.message, type: 'updated' } ) );
     745
     746                // Inject the activity into the stream only if it hasn't been done already (HeartBeat).
     747                } else if ( ! $( '#activity-' + response.id  ).length ) {
     748
     749                    // It's the very first activity, let's make sure the container can welcome it!
     750                    if ( ! $( '#activity-stream ul.activity-list').length ) {
     751                        $( '#activity-stream' ).html( $( '<ul></ul>').addClass( 'activity-list item-list bp-list' ) );
     752                    }
     753
     754                    // Prepend the activity.
     755                    bp.Nouveau.inject( '#activity-stream ul.activity-list', response.activity, 'prepend' );
     756                }
    737757            } ).fail( function( response ) {
    738758
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js

    r12036 r12038  
    104104            }
    105105
    106             if ( undefined !== property && store[property] ) {
    107                 return store[property];
     106            if ( undefined !== property ) {
     107                return store[property] || false;
    108108            }
    109109
Note: See TracChangeset for help on using the changeset viewer.