Skip to:
Content

BuddyPress.org

Ticket #8426: 8426.3.patch

File 8426.3.patch, 3.9 KB (added by imath, 3 years ago)
  • src/bp-messages/bp-messages-notifications.php

    diff --git src/bp-messages/bp-messages-notifications.php src/bp-messages/bp-messages-notifications.php
    index 8b700de04..44a3f1b0f 100644
    add_action( 'thread_loop_start', 'bp_messages_screen_conversation_mark_notificat 
    215215 * @since 3.0.0
    216216 *
    217217 * @param int $thread_id ID of the thread being marked as read.
     218 * @param int $num_rows The number of affected rows by the "mark read" update query.
    218219 */
    219 function bp_messages_mark_notification_on_mark_thread( $thread_id ) {
     220function bp_messages_mark_notification_on_mark_thread( $thread_id, $num_rows = 0 ) {
     221        if ( ! $num_rows ) {
     222                return;
     223        }
     224
    220225        $thread_messages = BP_Messages_Thread::get_messages( $thread_id );
    221226
    222227        foreach ( $thread_messages as $thread_message ) {
    223228                bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $thread_message->id, buddypress()->messages->id, 'new_message' );
    224229        }
    225230}
    226 add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread' );
     231add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread', 10, 2 );
    227232
    228233/**
    229234 * When a message is deleted, delete corresponding notifications.
  • src/bp-messages/classes/class-bp-messages-thread.php

    diff --git src/bp-messages/classes/class-bp-messages-thread.php src/bp-messages/classes/class-bp-messages-thread.php
    index 770e58434..34049f007 100644
    class BP_Messages_Thread { 
    625625                        bp_displayed_user_id() :
    626626                        bp_loggedin_user_id();
    627627
    628                 $bp     = buddypress();
    629                 $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 ) );
     628                $bp       = buddypress();
     629                $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 ) );
    630630
    631631                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    632632                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    class BP_Messages_Thread { 
    635635                 * Fires when messages thread was marked as read.
    636636                 *
    637637                 * @since 2.8.0
     638                 * @since 8.0.0 Passes the number of affected rows into the action.
    638639                 *
    639640                 * @param int $thread_id The message thread ID.
     641                 * @param int|false $num_rows The number of affected rows by the update query.
     642                 *                            False on error.
    640643                 */
    641                 do_action( 'messages_thread_mark_as_read', $thread_id );
     644                do_action( 'messages_thread_mark_as_read', $thread_id, $num_rows );
    642645
    643                 return $retval;
     646                return $num_rows;
    644647        }
    645648
    646649        /**
    class BP_Messages_Thread { 
    660663                        bp_displayed_user_id() :
    661664                        bp_loggedin_user_id();
    662665
    663                 $bp     = buddypress();
    664                 $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 ) );
     666                $bp       = buddypress();
     667                $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 ) );
    665668
    666669                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    667670                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    class BP_Messages_Thread { 
    670673                 * Fires when messages thread was marked as unread.
    671674                 *
    672675                 * @since 2.8.0
     676                 * @since 8.0.0 Passes the number of affected rows into the action.
    673677                 *
    674678                 * @param int $thread_id The message thread ID.
     679                 * @param int|false $num_rows The number of affected rows by the update query.
     680                 *                            False on error.
    675681                 */
    676                 do_action( 'messages_thread_mark_as_unread', $thread_id );
     682                do_action( 'messages_thread_mark_as_unread', $thread_id, $num_rows );
    677683
    678                 return $retval;
     684                return $num_rows;
    679685        }
    680686
    681687        /**