Skip to:
Content

BuddyPress.org

Changeset 10038


Ignore:
Timestamp:
08/07/2015 02:07:41 PM (6 years ago)
Author:
boonebgorges
Message:

BP_Messages_Thread objects should always have last_message_* properties set.

Previously, they were only set in the context of a template loop.

Props jdgrimes.
Fixes #6580.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-template.php

    r9946 r10038  
    18471847        $this->thread        = new BP_Messages_Thread( $thread_id, $order, $args );
    18481848        $this->message_count = count( $this->thread->messages );
    1849 
    1850         $last_message_index                 = $this->message_count - 1;
    1851         $this->thread->last_message_id      = $this->thread->messages[ $last_message_index ]->id;
    1852         $this->thread->last_message_date    = $this->thread->messages[ $last_message_index ]->date_sent;
    1853         $this->thread->last_sender_id       = $this->thread->messages[ $last_message_index ]->sender_id;
    1854         $this->thread->last_message_subject = $this->thread->messages[ $last_message_index ]->subject;
    1855         $this->thread->last_message_content = $this->thread->messages[ $last_message_index ]->message;
    18561849    }
    18571850
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r9951 r10038  
    2929     *
    3030     * @since BuddyPress (1.0.0)
    31      * @var object
     31     * @var array
    3232     */
    3333    public $messages;
     
    3737     *
    3838     * @since BuddyPress (1.0.0)
    39      * @var object
     39     * @var array
    4040     */
    4141    public $recipients;
     
    164164            $this->messages = array_reverse( $this->messages );
    165165        }
     166
     167        $last_message_index         = count( $this->messages ) - 1;
     168        $this->last_message_id      = $this->messages[ $last_message_index ]->id;
     169        $this->last_message_date    = $this->messages[ $last_message_index ]->date_sent;
     170        $this->last_sender_id       = $this->messages[ $last_message_index ]->sender_id;
     171        $this->last_message_subject = $this->messages[ $last_message_index ]->subject;
     172        $this->last_message_content = $this->messages[ $last_message_index ]->message;
    166173
    167174        foreach ( (array) $this->messages as $key => $message ) {
  • trunk/tests/phpunit/testcases/messages/class.bp-messages-thread.php

    r9819 r10038  
    403403        $this->assertEquals( null, BP_Messages_Thread::is_valid( 999 ) );
    404404    }
     405
     406    /**
     407     * @group last_message
     408     */
     409    public function test_last_message_populated() {
     410        $u1 = $this->factory->user->create();
     411        $u2 = $this->factory->user->create();
     412
     413        $date = bp_core_current_time();
     414
     415        $t1 = $this->factory->message->create( array(
     416            'sender_id' => $u1,
     417            'recipients' => array( $u2 ),
     418            'subject' => 'Foo',
     419            'date_sent' => $date,
     420            'content' => 'Bar and baz.',
     421        ) );
     422
     423        $thread = new BP_Messages_Thread( $t1 );
     424
     425        $this->assertNotNull( $thread->last_message_id );
     426        $this->assertEquals( 'Foo', $thread->last_message_subject );
     427        $this->assertEquals( $u1, $thread->last_sender_id );
     428        $this->assertEquals( $date, $thread->last_message_date );
     429        $this->assertEquals( 'Bar and baz.', $thread->last_message_content );
     430    }
    405431}
Note: See TracChangeset for help on using the changeset viewer.