diff --git a/src/bp-messages/bp-messages-notifications.php b/src/bp-messages/bp-messages-notifications.php
index 176a950d6..3f881a882 100644
a
|
b
|
add_action( 'thread_loop_start', 'bp_messages_screen_conversation_mark_notificat |
261 | 261 | * @since 3.0.0 |
262 | 262 | * |
263 | 263 | * @param int $thread_id ID of the thread being marked as read. |
| 264 | * @param int $user_id ID of the user thread will be marked as unread. |
| 265 | * @param int $num_rows The number of affected rows by the "mark read" update query. |
264 | 266 | */ |
265 | | function bp_messages_mark_notification_on_mark_thread( $thread_id ) { |
266 | | $thread_messages = BP_Messages_Thread::get_messages( $thread_id ); |
| 267 | function bp_messages_mark_notification_on_mark_thread( $thread_id, $user_id, $num_rows = 0 ) { |
| 268 | global $wpdb; |
| 269 | $bp = buddypress(); |
267 | 270 | |
268 | | foreach ( $thread_messages as $thread_message ) { |
269 | | bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $thread_message->id, buddypress()->messages->id, 'new_message' ); |
| 271 | if ( ! $num_rows ) { |
| 272 | return; |
270 | 273 | } |
| 274 | |
| 275 | $wpdb->query( $wpdb->prepare( "UPDATE {$bp->notifications->table_name} SET is_new=%d WHERE user_id=%d AND component_action=%s AND is_new=%d AND item_id IN (SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id=%d)", 0, $user_id, 'new_message', 1, $thread_id ) ); |
271 | 276 | } |
272 | | add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread' ); |
| 277 | add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread', 10, 3 ); |
273 | 278 | |
274 | 279 | /** |
275 | 280 | * When a message is deleted, delete corresponding notifications. |
diff --git a/src/bp-messages/classes/class-bp-messages-thread.php b/src/bp-messages/classes/class-bp-messages-thread.php
index 8a2845d21..f177ae335 100644
a
|
b
|
class BP_Messages_Thread { |
763 | 763 | bp_loggedin_user_id(); |
764 | 764 | } |
765 | 765 | |
766 | | $bp = buddypress(); |
767 | | $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) ); |
| 766 | $bp = buddypress(); |
| 767 | $num_rows = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) ); |
768 | 768 | |
769 | 769 | wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' ); |
770 | 770 | wp_cache_delete( $user_id, 'bp_messages_unread_count' ); |
… |
… |
class BP_Messages_Thread { |
774 | 774 | * |
775 | 775 | * @since 2.8.0 |
776 | 776 | * @since 9.0.0 Added the `user_id` parameter. |
| 777 | * @since 10.0.0 Passes the number of affected rows into the action. |
777 | 778 | * |
778 | 779 | * @param int $thread_id The message thread ID. |
779 | 780 | * @param int $user_id The user the thread will be marked as read. |
| 781 | * @param bool|int $num_rows Number of threads marked as unread or false on error. |
780 | 782 | */ |
781 | | do_action( 'messages_thread_mark_as_read', $thread_id, $user_id ); |
| 783 | do_action( 'messages_thread_mark_as_read', $thread_id, $user_id, $num_rows ); |
782 | 784 | |
783 | | return $retval; |
| 785 | return $num_rows; |
784 | 786 | } |
785 | 787 | |
786 | 788 | /** |
… |
… |
class BP_Messages_Thread { |
807 | 809 | bp_loggedin_user_id(); |
808 | 810 | } |
809 | 811 | |
810 | | $bp = buddypress(); |
811 | | $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) ); |
| 812 | $bp = buddypress(); |
| 813 | $num_rows = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) ); |
812 | 814 | |
813 | 815 | wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' ); |
814 | 816 | wp_cache_delete( $user_id, 'bp_messages_unread_count' ); |
… |
… |
class BP_Messages_Thread { |
818 | 820 | * |
819 | 821 | * @since 2.8.0 |
820 | 822 | * @since 9.0.0 Added the `$user_id` parameter. |
821 | | * @since 10.0.0 Added the `$retval` parameter. |
| 823 | * @since 10.0.0 Added the `$num_rows` parameter. |
822 | 824 | * |
823 | 825 | * @param int $thread_id The message thread ID. |
824 | 826 | * @param int $user_id The user the thread will be marked as unread. |
825 | | * @param bool|int $retval =Number of threads marked as unread or false on error. |
| 827 | * @param bool|int $num_rows Number of threads marked as unread or false on error. |
826 | 828 | */ |
827 | | do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id, $retval ); |
| 829 | do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id, $num_rows ); |
828 | 830 | |
829 | | return $retval; |
| 831 | return $num_rows; |
830 | 832 | } |
831 | 833 | |
832 | 834 | /** |