Skip to:
Content

BuddyPress.org

Ticket #7774: 7774.3.patch

File 7774.3.patch, 5.6 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..501da3b01 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 context = bp.Nouveau.Activity.getContext;
     712                                    toPrepend = context.areUpdatesListed() && context.isInSearch( response.activity );
    713713
    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                                         }
     714                                // Should we prepend the posted activity to the stream ?
     715                                if ( toPrepend ) {
     716                                        toPrepend = context[ self.model.get( 'object' ) ].prependNewItems( response );
    723717                                }
    724718
    725719                                // Reset the form
    726720                                self.resetForm();
    727721
    728                                 // Stop here if the activity has been added to the stream
    729                                 if ( prepended ) {
    730                                         return;
    731                                 }
     722                                // Display a successful feedback if the acticity is not consistent with the displayed stream.
     723                                if ( ! toPrepend ) {
     724                                        self.views.add( new bp.Views.activityFeedback( { value: response.message, type: 'updated' } ) );
     725
     726                                // Inject the activity into the stream only if it hasn't been done already (HeartBeat).
     727                                } else if ( ! $( '#activity-' + response.id  ).length ) {
    732728
    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' } ) );
     729                                        // It's the very first activity, let's make sure the container can welcome it!
     730                                        if ( ! $( '#activity-stream ul.activity-list').length ) {
     731                                                $( '#activity-stream' ).html( $( '<ul></ul>').addClass( 'activity-list item-list bp-list' ) );
     732                                        }
     733
     734                                        // Prepend the activity.
     735                                        bp.Nouveau.inject( '#activity-stream ul.activity-list', response.activity, 'prepend' );
     736                                }
    737737                        } ).fail( function( response ) {
    738738
    739739                                self.model.set( 'errors', { type: 'error', value: response.message } );
  • src/bp-templates/bp-nouveau/js/buddypress-activity.js

    diff --git src/bp-templates/bp-nouveau/js/buddypress-activity.js src/bp-templates/bp-nouveau/js/buddypress-activity.js
    index e47543c2b..f992d283d 100644
    window.bp = window.bp || {}; 
    5252                        };
    5353                },
    5454
     55                getContext: {
     56                        /**
     57                         * Checks content match search terms.
     58                         *
     59                         * @return {boolean} True if there's no search all activities are matching, or
     60                         *                   there's a search and content matches it. False otherwise.
     61                         */
     62                        isInSearch: function( content ) {
     63                                var searchTerms = $( '[data-bp-search="activity"] input[type="search"]' ).val(), matches = {};
     64
     65                                if ( ! content ) {
     66                                        return false;
     67                                }
     68
     69                                if ( searchTerms ) {
     70                                        searchTerms = new RegExp( searchTerms, 'im' );
     71                                        matches = content.match( searchTerms );
     72                                }
     73
     74                                return ! searchTerms || null !== matches;
     75                        },
     76                        /**
     77                         * Checks Activity Updates are listed.
     78                         *
     79                         * @return {boolean} True if all activity types are listed, or only
     80                         *                   activity updates are listed. False otherwise.
     81                         */
     82                        areUpdatesListed: function() {
     83                                var filter = bp.Nouveau.getStorage( 'bp-activity', 'filter' );
     84
     85                                return ! filter || 0 === parseInt( filter, 10 ) || 'activity_update' === filter;
     86                        },
     87                        user: {
     88                                /**
     89                                 * Conditions to prepend new user activities to the stream.
     90                                 *
     91                                 * @param  {object} item  The posted item.
     92                                 * @return {boolean}      True if the user is on his profile, or if all items
     93                                 *                        are listed in the Activity directory. False otherwise.
     94                                 */
     95                                prependNewItems: function( item ) {
     96                                        var scope = bp.Nouveau.getStorage( 'bp-activity', 'scope' );
     97                                        item = $.extend( { 'is_directory': false }, item );
     98
     99                                        if ( item.is_directory ) {
     100                                                return 'all' === scope;
     101                                        }
     102
     103                                        return true;
     104                                }
     105                        },
     106                        group: {
     107                                /**
     108                                 * Conditions to prepend new group activities to the stream.
     109                                 *
     110                                 * @param  {object} item  The posted item.
     111                                 * @return {boolean}      True if the user is on the group's profile, or if group items
     112                                 *                        are listed into the Activity directory. False otherwise.
     113                                 */
     114                                prependNewItems: function( item ) {
     115                                        var scope = bp.Nouveau.getStorage( 'bp-activity', 'scope' );
     116                                        item = $.extend( { 'is_directory': false, 'is_private': false }, item );
     117
     118                                        if ( item.is_directory ) {
     119                                                return 'groups' === scope || ! item.is_private;
     120                                        }
     121
     122                                        return true;
     123                                }
     124                        }
     125                },
     126
    55127                /**
    56128                 * [addListeners description]
    57129                 */
  • 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 ef9a9cc7b..12f5f1ae9 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;