[buddypress-trac] [BuddyPress Trac] #8750: Unread count not set for message threads

buddypress-trac noreply at wordpress.org
Mon Oct 10 23:33:26 UTC 2022


#8750: Unread count not set for message threads
--------------------------------------+---------------------
 Reporter:  sjregan                   |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  10.5.0
Component:  Messages                  |     Version:  10.4.0
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |
--------------------------------------+---------------------

Comment (by sjregan):

 Hi @imath, thanks for the response and the patch.

 There's a few of things to note:

 1. The BP_Messages_Thread::populate() method accepts $user_id in the
 arguments but defaults to the displayed or logged in user.

 https://github.com/buddypress/buddypress/blob/master/src/bp-
 messages/classes/class-bp-messages-thread.php#L149

 2. The BP_Messages_Box_Template class also accepts the $user_id through
 its arguments and passes it to
 BP_Messages_Thread::get_current_threads_for_user(), however,
 BP_Messages_Thread::get_current_threads_for_user() does NOT pass on the
 $user_id to new BP_Messages_Thread().

 https://github.com/buddypress/buddypress/blob/master/src/bp-
 messages/classes/class-bp-messages-box-template.php#L146-L175

 So, if you provide BP_Messages_Thread::get_current_threads_for_user() with
 a $user_id, you will not get the unread_count for that $user_id. You will
 get an unread count, just not the correct one for the $user_id you
 provided.

 This is evident when using the REST API:
 https://github.com/buddypress/BP-REST/blob/master/includes/bp-
 messages/classes/class-bp-rest-messages-endpoint.php#L123

 My PR included a test that captured this scenario and provided a fix. Here
 is a single commit containing just the test so you can apply it your patch
 and see the issue is not fully resolved:

 https://github.com/sjregan/buddypress/commit/0c930bf9dcd94dda72bdc13e9e83cfb3a92c6a3c

 3. BP_Messages_Thread::get_recipients() includes the
 'bp_messages_thread_get_recipients' filter. So even with the array_slice()
 issue fixed (and the missing $user_id parameter to the BP_Messages_Thread
 constructor), you cannot rely on the results of get_recipients() always
 including the $user_id recipient.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8750#comment:6>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list