Skip to:
Content

BuddyPress.org

Ticket #8426: 8426.5.patch

File 8426.5.patch, 4.5 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 176a950d6..3f881a882 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 ) {
    266         $thread_messages = BP_Messages_Thread::get_messages( $thread_id );
     267function bp_messages_mark_notification_on_mark_thread( $thread_id, $user_id, $num_rows = 0 ) {
     268        global $wpdb;
     269        $bp = buddypress();
    267270
    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;
    270273        }
     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 ) );
    271276}
    272 add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread' );
     277add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread', 10, 3 );
    273278
    274279/**
    275280 * 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 8a2845d21..f177ae335 100644
    a b class BP_Messages_Thread { 
    763763                                bp_loggedin_user_id();
    764764                }
    765765
    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 ) );
    768768
    769769                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    770770                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    class BP_Messages_Thread { 
    774774                 *
    775775                 * @since 2.8.0
    776776                 * @since 9.0.0 Added the `user_id` parameter.
     777                 * @since 10.0.0 Passes the number of affected rows into the action.
    777778                 *
    778779                 * @param int $thread_id The message thread ID.
    779780                 * @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.
    780782                 */
    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 );
    782784
    783                 return $retval;
     785                return $num_rows;
    784786        }
    785787
    786788        /**
    class BP_Messages_Thread { 
    807809                                bp_loggedin_user_id();
    808810                }
    809811
    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 ) );
    812814
    813815                wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    814816                wp_cache_delete( $user_id, 'bp_messages_unread_count' );
    class BP_Messages_Thread { 
    818820                 *
    819821                 * @since 2.8.0
    820822                 * @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.
    822824                 *
    823825                 * @param int      $thread_id The message thread ID.
    824826                 * @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.
    826828                 */
    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 );
    828830
    829                 return $retval;
     831                return $num_rows;
    830832        }
    831833
    832834        /**