Skip to:
Content

BuddyPress.org

Ticket #7847: 7847.2.patch

File 7847.2.patch, 4.7 KB (added by imath, 7 years ago)

Improves first patch by making sure bp_is_messages_conversation() is true in AJAX

  • src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php

    diff --git src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php
    index c5ddaddf9..34844c983 100644
     
    272272
    273273        </div>
    274274
    275         <?php bp_nouveau_messages_hook( 'before', 'content' ); ?>
     275        <# if ( data.beforeContent ) { #>
     276                <div class="bp-messages-hook before-message-content">{{{data.beforeContent}}}</div>
     277        <# } #>
    276278
    277         <div class="message-content"><# print( data.content ) #></div>
     279        <div class="message-content">{{{data.content}}}</div>
    278280
    279         <?php bp_nouveau_messages_hook( 'after', 'content' ); ?>
     281        <# if ( data.afterContent ) { #>
     282                <div class="bp-messages-hook after-message-content">{{{data.afterContent}}}</div>
     283        <# } #>
    280284
    281285</script>
    282286
  • src/bp-templates/bp-nouveau/includes/messages/ajax.php

    diff --git src/bp-templates/bp-nouveau/includes/messages/ajax.php src/bp-templates/bp-nouveau/includes/messages/ajax.php
    index 16c80a7c8..f49175016 100644
    function bp_nouveau_ajax_messages_send_reply() { 
    134134                wp_send_json_error( $response );
    135135        }
    136136
    137         // Get the message bye pretending we're in the message loop.
     137        // Get the message by pretending we're in the message loop.
    138138        global $thread_template;
    139139
     140        $bp           = buddypress();
     141        $reset_action = $bp->current_action;
     142
     143        // Override bp_current_action().
     144        $bp->current_action = 'view';
     145
    140146        bp_thread_has_messages( array( 'thread_id' => (int) $_POST['thread_id'] ) );
    141147
    142148        // Set the current message to the 2nd last.
    function bp_nouveau_ajax_messages_send_reply() { 
    182188                $reply['is_starred'] = array_search( 'unstar', explode( '/', $star_link ) );
    183189        }
    184190
     191        $extra_content = bp_nouveau_messages_catch_hook_content( array(
     192                'beforeContent' => 'bp_before_message_content',
     193                'afterContent'  => 'bp_after_message_content',
     194        ) );
     195
     196        if ( array_filter( $extra_content ) ) {
     197                $reply = array_merge( $reply, $extra_content );
     198        }
     199
    185200        // Clean up the loop.
    186201        bp_thread_messages();
    187202
     203        // Remove the bp_current_action() override.
     204        $bp->current_action = $reset_action;
     205
    188206        wp_send_json_success( array(
    189207                'messages' => array( $reply ),
    190208                'feedback' => __( 'Your reply was sent successfully', 'buddypress' ),
    function bp_nouveau_ajax_get_thread_messages() { 
    356374                wp_send_json_error( $response );
    357375        }
    358376
    359         $thread_id = (int) $_POST['id'];
     377        $thread_id    = (int) $_POST['id'];
     378        $bp           = buddypress();
     379        $reset_action = $bp->current_action;
     380
     381        // Override bp_current_action().
     382        $bp->current_action = 'view';
    360383
    361384        // Simulate the loop.
    362385        if ( ! bp_thread_has_messages( array( 'thread_id' => $thread_id ) ) ) {
     386                // Remove the bp_current_action() override.
     387                $bp->current_action = $reset_action;
     388
    363389                wp_send_json_error( $response );
    364390        }
    365391
    function bp_nouveau_ajax_get_thread_messages() { 
    422448                        $thread->messages[ $i ]['star_nonce'] = wp_create_nonce( 'bp-messages-star-' . bp_get_the_thread_message_id() );
    423449                }
    424450
     451                $extra_content = bp_nouveau_messages_catch_hook_content( array(
     452                        'beforeContent' => 'bp_before_message_content',
     453                        'afterContent'  => 'bp_after_message_content',
     454                ) );
     455
     456                if ( array_filter( $extra_content ) ) {
     457                        $thread->messages[ $i ] = array_merge( $thread->messages[ $i ], $extra_content );
     458                }
     459
    425460                $i += 1;
    426461        endwhile;
    427462
    428463        $thread->messages = array_filter( $thread->messages );
    429464
     465        // Remove the bp_current_action() override.
     466        $bp->current_action = $reset_action;
     467
    430468        wp_send_json_success( $thread );
    431469}
    432470
  • src/bp-templates/bp-nouveau/includes/messages/functions.php

    diff --git src/bp-templates/bp-nouveau/includes/messages/functions.php src/bp-templates/bp-nouveau/includes/messages/functions.php
    index 191a85381..1784cedb2 100644
    function bp_nouveau_messages_notification_filters() { 
    444444                )
    445445        );
    446446}
     447
     448/**
     449 * Fires Messages Legacy hooks to catch the content and add them
     450 * as extra keys to the JSON Messages UI reply.
     451 *
     452 * @since 3.0.1
     453 *
     454 * @param array $hooks The list of hooks to fire.
     455 * @return array       An associative containing the caught content.
     456 */
     457function bp_nouveau_messages_catch_hook_content( $hooks = array() ) {
     458        $content = array();
     459
     460        ob_start();
     461        foreach ( $hooks as $js_key => $hook ) {
     462                if ( ! has_action( $hook ) ) {
     463                        continue;
     464                }
     465
     466                // Fire the hook.
     467                do_action( $hook );
     468
     469                // Catch the content.
     470                $content[ $js_key ] = ob_get_contents();
     471
     472                // Clean the buffer.
     473                ob_clean();
     474        }
     475        ob_end_clean();
     476
     477        return $content;
     478}