Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/16/2015 10:59:18 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Messages: Modify message thread queries to exclude messages in deleted threads from "Starred" messages.

This change ensures that deleted messages do not appear in the "Starred" section of a member's private messages. Previously, it was possible to delete a private message thread, and still have it come back to life in the "Starred" messages section.

Fixes #6483. Props r-a-y. (trunk, for 2.4.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/messages/star.php

    r9846 r9951  
    108108
    109109        /**
     110         * @group bp_messages_filter_starred_message_threads
     111         */
     112        public function test_get_starred_threads_should_not_include_deleted_thread() {
     113                $old_current_user = get_current_user_id();
     114                $u1 = $this->factory->user->create();
     115                $u2 = $this->factory->user->create();
     116
     117                // create three threads
     118                $t1 = $this->factory->message->create( array(
     119                        'sender_id'  => $u1,
     120                        'recipients' => array( $u2 ),
     121                        'subject'    => 'A',
     122                ) );
     123                $t2 = $this->factory->message->create( array(
     124                        'sender_id'  => $u1,
     125                        'recipients' => array( $u2 ),
     126                        'subject'    => 'B',
     127                ) );
     128                $t3 = $this->factory->message->create( array(
     129                        'sender_id'  => $u1,
     130                        'recipients' => array( $u2 ),
     131                        'subject'    => 'C',
     132                ) );
     133
     134                // grab the message ids as individual variables
     135                list( $m1 ) = $this->get_message_ids( $t1 );
     136                list( $m2 ) = $this->get_message_ids( $t2 );
     137                list( $m3 ) = $this->get_message_ids( $t3 );
     138
     139                // star all threads
     140                bp_messages_star_set_action( array(
     141                        'user_id'    => $u2,
     142                        'message_id' => $m1,
     143                ) );
     144                bp_messages_star_set_action( array(
     145                        'user_id'    => $u2,
     146                        'message_id' => $m2,
     147                ) );
     148                bp_messages_star_set_action( array(
     149                        'user_id'    => $u2,
     150                        'message_id' => $m3,
     151                ) );
     152
     153                // delete the second thread
     154                $this->set_current_user( $u2 );
     155                messages_delete_thread( $t2 );
     156
     157                // load the starred threads loop
     158                global $messages_template;
     159                add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
     160                bp_has_message_threads();
     161                remove_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
     162
     163                // assert that second thread isn't in starred thread loop
     164                $thread_ids = wp_list_pluck( $messages_template->threads, 'thread_id' );
     165                $this->assertFalse( in_array( $t2, $thread_ids ) );
     166
     167                // reset
     168                $this->set_current_user( $old_current_user );
     169        }
     170
     171        /**
    110172         * Helper method to grab the message IDs from a message thread.
    111173         *
Note: See TracChangeset for help on using the changeset viewer.