Skip to:
Content

BuddyPress.org

Ticket #8426: 8426.4.patch

File 8426.4.patch, 4.3 KB (added by oztaser, 3 years ago)
  • src/bp-messages/bp-messages-notifications.php

    diff --git a/src/bp-messages/bp-messages-notifications.php b/src/bp-messages/bp-messages-notifications.php
    index e2855d746..cb7eff9e0 100644
    a b add_action( 'thread_loop_start', 'bp_messages_screen_conversation_mark_notificat 
    261261 * @since 3.0.0
    262262 *
    263263 * @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.
    264266 */
    265 function bp_messages_mark_notification_on_mark_thread( $thread_id ) {
     267function bp_messages_mark_notification_on_mark_thread( $thread_id, $user_id, $num_rows = 0 ) {
     268        if ( ! $num_rows ) {
     269                return;
     270        }
     271
    266272        $thread_messages = BP_Messages_Thread::get_messages( $thread_id );
    267273
    268274        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' );
     275                bp_notifications_mark_notifications_by_item_id( $user_id, $thread_message->id, buddypress()->messages->id, 'new_message' );
    270276        }
    271277}
    272 add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread' );
     278add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread', 10, 3 );
    273279
    274280/**
    275281 * When a message is deleted, delete corresponding notifications.
  • 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 bc5f93a5e..2fe779c0f 100644
    a b class BP_Messages_Thread { 
    655655                                bp_loggedin_user_id();
    656656                }
    657657
    658                 $bp     = buddypress();
    659                 $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 ) );
     658                $bp       = buddypress();
     659                $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 ) );
    660660
    661661                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    662662                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    class BP_Messages_Thread { 
    666666                 *
    667667                 * @since 2.8.0
    668668                 * @since 9.0.0 Added the `user_id` parameter.
     669                 * @since 10.0.0 Passes the number of affected rows into the action.
    669670                 *
    670671                 * @param int $thread_id The message thread ID.
    671672                 * @param int $user_id   The user the thread will be marked as read.
     673                 * @param bool|int $num_rows Number of threads marked as unread or false on error.
    672674                 */
    673                 do_action( 'messages_thread_mark_as_read', $thread_id, $user_id );
     675                do_action( 'messages_thread_mark_as_read', $thread_id, $user_id, $num_rows );
    674676
    675                 return $retval;
     677                return $num_rows;
    676678        }
    677679
    678680        /**
    class BP_Messages_Thread { 
    699701                                bp_loggedin_user_id();
    700702                }
    701703
    702                 $bp     = buddypress();
    703                 $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 ) );
     704                $bp       = buddypress();
     705                $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 ) );
    704706
    705707                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    706708                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    class BP_Messages_Thread { 
    710712                 *
    711713                 * @since 2.8.0
    712714                 * @since 9.0.0  Added the `$user_id` parameter.
    713                  * @since 10.0.0 Added the `$retval` parameter.
     715                 * @since 10.0.0 Added the `$num_rows` parameter.
    714716                 *
    715717                 * @param int      $thread_id The message thread ID.
    716718                 * @param int      $user_id   The user the thread will be marked as unread.
    717                  * @param bool|int $retval     =Number of threads marked as unread or false on error.
     719                 * @param bool|int $num_rows    Number of threads marked as unread or false on error.
    718720                 */
    719                 do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id, $retval );
     721                do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id, $num_rows );
    720722
    721                 return $retval;
     723                return $num_rows;
    722724        }
    723725
    724726        /**