Skip to:
Content

BuddyPress.org

Ticket #7774: 7774.2.patch

File 7774.2.patch, 3.9 KB (added by imath, 8 years ago)
  • src/bp-templates/bp-nouveau/js/buddypress-activity-post-form.js

    diff --git src/bp-templates/bp-nouveau/js/buddypress-activity-post-form.js src/bp-templates/bp-nouveau/js/buddypress-activity-post-form.js
    index 9a50fb7bc..2b8ce57a8 100644
    window.bp = window.bp || {}; 
    708708                        }
    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;
     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                                }
    713720
    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                                     ) {
     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                                }
    718729
    719                                         if ( ! $( '#activity-' + response.id  ).length ) {
    720                                                 bp.Nouveau.inject( '#activity-stream ul.activity-list', response.activity, 'prepend' );
    721                                                 prepended = true;
    722                                         }
     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 ) )
     737                                                                || ( self.model.get( 'object' ) + 's'  === store.scope );
    723738                                }
    724739
    725740                                // Reset the form
    726741                                self.resetForm();
    727742
    728                                 // Stop here if the activity has been added to the stream
    729                                 if ( prepended ) {
    730                                         return;
    731                                 }
     743                                // Display a successful feedback if the acticity is not consistent with the displayed stream.
     744                                if ( ! toPrepend ) {
     745                                        self.views.add( new bp.Views.activityFeedback( { value: response.message, type: 'updated' } ) );
    732746
    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' } ) );
     747                                // Inject the activity into the stream only if it hasn't been done already (HeartBeat).
     748                                } else if ( ! $( '#activity-' + response.id  ).length ) {
     749
     750                                        // It's the very first activity, let's make sure the container can welcome it!
     751                                        if ( ! $( '#activity-stream ul.activity-list').length ) {
     752                                                $( '#activity-stream' ).html( $( '<ul></ul>').addClass( 'activity-list item-list bp-list' ) );
     753                                        }
     754
     755                                        // Prepend the activity.
     756                                        bp.Nouveau.inject( '#activity-stream ul.activity-list', response.activity, 'prepend' );
     757                                }
    737758                        } ).fail( function( response ) {
    738759
    739760                                self.model.set( 'errors', { type: 'error', value: response.message } );
  • src/bp-templates/bp-nouveau/js/buddypress-nouveau.js

    diff --git src/bp-templates/bp-nouveau/js/buddypress-nouveau.js src/bp-templates/bp-nouveau/js/buddypress-nouveau.js
    index 763c74d54..8d9930282 100644
    window.bp = window.bp || {}; 
    103103                                store = {};
    104104                        }
    105105
    106                         if ( undefined !== property && store[property] ) {
    107                                 return store[property];
     106                        if ( undefined !== property ) {
     107                                return store[property] || false;
    108108                        }
    109109
    110110                        return store;