Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/11/2022 07:22:19 PM (3 years ago)
Author:
imath
Message:

BP Messages: make sure Threads unread count is consistent

[13102] introduced a regression considering the way we used to set a thread's unread count. This count is set using the list of recipient objects (which include an unread_count property for each user object) by checking for the requested user ID into this list to find the corresponding unread count.

Slicing this list into smaller parts to paginate recipients results introduced potential cases where the requested user ID wasn't found into this paginated list of recipients.

Before doing the slice operation, we need to set the requested user ID thread's unread count to be sure it's the right one and not a null value.

Props sjregan

Fixes #8750 (branch 10.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/10.0/src/bp-messages/classes/class-bp-messages-thread.php

    r13196 r13340  
    201201        }
    202202
    203         // Fetch the recipients.
     203        // Fetch the recipients and set the displayed/logged in user's unread count.
    204204        $this->recipients = $this->get_recipients( $thread_id, $r );
    205 
    206         // Get the unread count for the user.
    207         if ( isset( $this->recipients[ $r['user_id'] ] ) ) {
    208             $this->unread_count = $this->recipients[ $r['user_id'] ]->unread_count;
    209         }
    210205
    211206        // Grab all message meta.
     
    312307        }
    313308
     309        // Set the unread count for the user.
     310        if ( isset( $r['user_id'] ) && $r['user_id'] && isset( $recipients[ $r['user_id'] ]->unread_count ) ) {
     311            $this->unread_count = (int) $recipients[ $r['user_id'] ]->unread_count;
     312        }
     313
    314314        // Paginate the results.
    315315        if ( ! empty( $recipients ) && $r['recipients_per_page'] && $r['recipients_page'] ) {
    316316            $start      = ( $r['recipients_page'] - 1 ) * ( $r['recipients_per_page'] );
    317             $recipients = array_slice( $recipients, $start, $r['recipients_per_page'] );
     317            $recipients = array_slice( $recipients, $start, $r['recipients_per_page'], true );
    318318        }
    319319
     
    757757                'ASC',
    758758                array(
     759                    'user_id'             => $r['user_id'],
    759760                    'update_meta_cache'   => false,
    760761                    'recipients_page'     => $r['recipients_page'],
Note: See TracChangeset for help on using the changeset viewer.