Skip to:
Content

BuddyPress.org

Ticket #8426: 8426.2.patch

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

     
    217217 * @param int $thread_id ID of the thread being marked as read.
    218218 */
    219219function bp_messages_mark_notification_on_mark_thread( $thread_id ) {
    220         $thread_messages = BP_Messages_Thread::get_messages( $thread_id );
     220        global $wpdb;
     221        $bp = buddypress();
    221222
    222         foreach ( $thread_messages as $thread_message ) {
    223                 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $thread_message->id, buddypress()->messages->id, 'new_message' );
     223        $unread_messages = $wpdb->get_results( $wpdb->prepare( "SELECT m.id FROM {$bp->messages->table_name_messages} AS m LEFT JOIN {$bp->notifications->table_name} AS n ON m.id = n.item_id WHERE m.thread_id=%d AND n.user_id=%d AND n.component_name=%s AND n.component_action=%s and n.is_new=%d", bp_loggedin_user_id(), $thread_id, $bp->messages->id, 'new_message', 1 ) );
     224
     225        // Bail if there are no unread PM notifications for the user.
     226        if ( true === empty( $new_pm_notifications ) ) {
     227                return;
    224228        }
     229
     230        foreach ( $unread_messages as $unread_message ) {
     231                bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $unread_message->id, buddypress()->messages->id, 'new_message' );
     232        }
    225233}
    226234add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread' );
    227235