Ticket #7540: patch7540.diff
| File patch7540.diff, 6.1 KB (added by , 9 years ago) |
|---|
-
src/bp-messages/bp-messages-actions.php
diff --git a/src/bp-messages/bp-messages-actions.php b/src/bp-messages/bp-messages-actions.php index d3b1287..a29d46b 100644
a b function messages_action_delete_message() { 296 296 add_action( 'bp_actions', 'messages_action_delete_message' ); 297 297 298 298 /** 299 * Process a request to quit a conversation (if multi-recipient) 300 * 301 * @return bool False on failure. 302 */ 303 function messages_action_quit_thread() { 304 305 if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'quit', 0 ) ) { 306 return false; 307 } 308 309 $thread_id = bp_action_variable( 1 ); 310 311 if ( !$thread_id || !is_numeric( $thread_id ) || !messages_check_thread_access( $thread_id ) ) { 312 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/view' ) ); 313 } else { 314 if ( ! check_admin_referer( 'messages_quit_thread' ) ) { 315 return false; 316 } 317 318 $thread = new BP_Messages_Thread( $thread_id ); 319 //--- only for multi-recipients threads, and not for the creator of the thread 320 if ( count( $thread->recipients ) < 2 or $thread->first_sender_id == bp_loggedin_user_id() ) { 321 return false; 322 } 323 if ( !messages_quit_thread( $thread_id, bp_loggedin_user_id() ) ) { 324 bp_core_add_message( __('There was an error quitting that conversation.', 'buddypress'), 'error' ); 325 } else { 326 bp_core_add_message( __('Conversation quitted.', 'buddypress') ); 327 } 328 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox' ) ); 329 } 330 } 331 add_action( 'bp_actions', 'messages_action_quit_thread' ); 332 333 /** 299 334 * Handle marking a single message thread as read. 300 335 * 301 336 * @since 2.2.0 -
src/bp-messages/bp-messages-functions.php
diff --git a/src/bp-messages/bp-messages-functions.php b/src/bp-messages/bp-messages-functions.php index 39a3c55..ad48e5c 100644
a b function messages_mark_thread_unread( $thread_id ) { 349 349 } 350 350 351 351 /** 352 * Quit a thread. 353 * 354 * Wrapper for {@link BP_Messages_Thread::quit_thread()}. 355 * 356 * @param int $thread_id ID of the thread. 357 * 358 * @return bool. 359 */ 360 function messages_quit_thread( $thread_id, $user_id = 0 ) { 361 return BP_Messages_Thread::quit_thread( $thread_id, $user_id); 362 } 363 364 /** 352 365 * Set messages-related cookies. 353 366 * 354 367 * Saves the 'bp_messages_send_to', 'bp_messages_subject', and -
src/bp-messages/bp-messages-template.php
diff --git a/src/bp-messages/bp-messages-template.php b/src/bp-messages/bp-messages-template.php index 12ec655..1a66066 100644
a b function bp_the_thread_subject() { 1620 1620 } 1621 1621 1622 1622 /** 1623 * Get the sender ID of the first message of the thread currently being iterated over. 1624 * 1625 * @return integer 1626 */ 1627 function bp_get_thread_first_sender_id() { 1628 global $thread_template; 1629 return $thread_template->thread->first_sender_id; 1630 } 1631 1632 /** 1623 1633 * Get a list of thread recipients or a "x recipients" string. 1624 1634 * 1625 1635 * In BuddyPress 2.2.0, this parts of this functionality were moved into the … … function bp_the_thread_delete_link() { 1996 2006 */ 1997 2007 return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) ); 1998 2008 } 2009 2010 /** 2011 * Output the URL for quitting the current thread. 2012 * 2013 * @since 2014 */ 2015 function bp_the_quit_thread_link() { 2016 echo esc_url( bp_get_the_quit_thread_link() ); 2017 } 2018 /** 2019 * Get the URL for quitting the current thread. 2020 * 2021 * @since 2022 * 2023 * @return string URL 2024 */ 2025 function bp_get_the_quit_thread_link() { 1999 2026 2027 /** 2028 * Filters the URL for quitting the current thread. 2029 * 2030 * @since 2031 * 2032 * @param string $value URL for quitting the current thread. 2033 * @param string $value Text indicating action being executed. 2034 */ 2035 return apply_filters( 'bp_get_message_quit_thread_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox/quit/' . bp_get_the_thread_id(), 'messages_quit_thread' ) ); 2036 } 2037 2000 2038 /** 2001 2039 * Output the 'Sent x hours ago' string for the current message. 2002 2040 * -
src/bp-messages/classes/class-bp-messages-thread.php
diff --git a/src/bp-messages/classes/class-bp-messages-thread.php b/src/bp-messages/classes/class-bp-messages-thread.php index c868d55..0beb0ca 100644
a b class BP_Messages_Thread { 96 96 * @var int 97 97 */ 98 98 public $last_sender_id; 99 100 /** 101 * The user ID of the author of the first message in this thread. 102 * 103 * @since 1.2.0 104 * @var int 105 */ 106 public $first_sender_id; 99 107 100 108 /** 101 109 * Sort order of the messages in this thread (ASC or DESC). … … class BP_Messages_Thread { 164 172 if ( empty( $this->messages ) || is_wp_error( $this->messages ) ) { 165 173 return false; 166 174 } 175 176 $this->first_sender_id = $this->messages[ 0 ]->sender_id; 167 177 168 178 // Flip if order is DESC. 169 179 if ( 'DESC' === $order ) { … … class BP_Messages_Thread { 675 685 676 686 return $retval; 677 687 } 688 689 /** 690 * Quite a multi-recipient thread. 691 * 692 * @since 693 * 694 * @param int $thread_id The message thread ID. 695 * 696 * @return bool. 697 */ 698 public static function quit_thread( $thread_id = 0, $user_id = 0 ) { 699 700 if ( empty( $user_id ) ) { 701 $user_id = bp_loggedin_user_id(); 702 } 703 global $wpdb; 704 705 $bp = buddypress(); 706 707 $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND user_id = %d", $thread_id, $user_id ) ); 708 709 wp_cache_delete( "thread_recipients_{$thread_id}", 'bp_messages' ); 710 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); 711 712 /** 713 * Fires when messages thread was quitted. 714 * 715 * @since 2.8.0 716 * 717 * @param int $thread_id The message thread ID. 718 */ 719 do_action( 'messages_thread_quitted', $thread_id, $user_id ); 720 721 return $retval; 722 } 678 723 679 724 /** 680 725 * Returns the total number of message threads for a user. … … class BP_Messages_Thread { 904 949 905 950 return (bool) ! $errors; 906 951 } 952 907 953 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)