Skip to:
Content

BuddyPress.org

Changeset 13278


Ignore:
Timestamp:
04/30/2022 10:44:32 AM (4 years ago)
Author:
imath
Message:

BP Nouveau: prevent anxious users to send a message more than once

In case the Ajax response takes a little more time to happen, frenetic clicks on the Messages UI "send" button are now neutralized.

Props comminski

See #8689 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-messages.js

    r13274 r13278  
    257257
    258258                sendMessage: function() {
    259                         if ( true === this.get( 'sending' ) ) {
    260                                 return;
    261                         }
    262 
    263                         this.set( 'sending', true, { silent: true } );
    264 
    265                         var sent = bp.ajax.post( 'messages_send_message', _.extend(
    266                                 {
    267                                         nonce: BP_Nouveau.messages.nonces.send
    268                                 },
    269                                 this.attributes
    270                         ) );
    271 
    272                         this.set( 'sending', false, { silent: true } );
     259                        var sent = bp.ajax.post(
     260                                'messages_send_message',
     261                                _.extend(
     262                                        { nonce: BP_Nouveau.messages.nonces.send },
     263                                        this.attributes
     264                                )
     265                        );
    273266
    274267                        return sent;
     
    569562                        if ( ! _.isNull( mention ) ) {
    570563                                sendToInput.val( '@' + _.escape( mention ) + ' ' );
    571                                 sendToInput.focus();
     564                                sendToInput.trigger( 'focus' );
    572565                        }
    573566                },
     
    593586
    594587                sendMessage: function( event ) {
    595                         var meta = {}, errors = [], self = this;
     588                        var meta = {}, errors = [], self = this,
     589                            button = event.currentTarget;
     590
    596591                        event.preventDefault();
    597592
    598593                        bp.Nouveau.Messages.removeFeedback();
     594                        $( button ).addClass( 'disabled' ).prop( 'disabled', true );
    599595
    600596                        // Set the content and meta.
     
    662658                        }
    663659
     660                        // Prevents multiple frenetic clicks!
     661                        if ( true === this.model.get( 'sending' ) ) {
     662                                return;
     663                        }
     664
    664665                        // Set meta.
    665                         this.model.set( 'meta', meta, { silent: true } );
     666                        this.model.set(
     667                                {
     668                                        sending: true,
     669                                        meta: meta
     670                                },
     671                                {
     672                                        silent: true
     673                                }
     674                        );
    666675
    667676                        // Send the message.
     
    685694                                        bp.Nouveau.Messages.displayFeedback( response.feedback, response.type );
    686695                                }
     696                        } ).always( function() {
     697                                self.model.set( 'sending', false, { silent: true } );
     698                                $( button ).removeClass( 'disabled' ).prop( 'disabled', false );
    687699                        } );
    688700                },
Note: See TracChangeset for help on using the changeset viewer.