Problem/Motivation
If you try to add a user to an existing thread, the added user will not see the thread on the /private-messages/
page, but the thread is displayed normally via a direct link (for example, /private-messages/1
).
Steps to reproduce
- install drupal
- install private_message module and enable it
- create 2 additional users
- create thread with 2 users
- send a some messages to the thread
- add third user to thread via code
Sample code for adding user to existing thread:
$thread_id = 1;
$thread = PrivateMessageThread::load($thread_id);
$user = User::load(3); // id of the user being added
$thread->addMember($user);
$thread->save();
And then, if you try to open the /private-messages/
page with a newly added user, he will not see the thread
But if you follow a direct link (for example, /private-messages/1
) the user will see the thread.
Proposed resolution
If you change the code for adding a user to the thread to this:
$thread_id = 1;
$thread = PrivateMessageThread::load($thread_id);
$user = User::load(3);
$thread->addMember($user);
$thread->addHistoryRecord($user); // <-- added line
$thread->save();
The user who was added to the thread will see it on the page /private-messages/