When posting a news article on my site's CMS, I create a new thread for that article, with the userid of that user that was posting the news item.
The code to do this is this:
I then create a thread watch
Everything appears to work correctly, and there is an entry in xf_thread_watch, but, when alerts are set to on, the user is not getting an alert.
However, if the user visits the thread (manually), and then somebody makes a post in it, an alert will appear without making any other changes.
It looks like alerts do not appear, because the user in who's name that thread was created, has not seen that thread. I do not believe this is normal behaviour.
Is there any way to programmatically make it look like the user has visited the thread at the same time the thread was made?
Thanks
The code to do this is this:
Code:
$forum = \XF::em()->find('XF:Forum', $forumid);
$user = \XF::em()->find('XF:User', $userid);
$thread = \XF::asVisitor($user, function() use ($forum, $title, $message)
{
$creator = \XF::service('XF:Thread\Creator', $forum);
$creator->setDiscussionState('visible');
$creator->setContent($title, $message);
$creator->setIsAutomated();
return $creator->save();
});
I then create a thread watch
Code:
$threadid = $thread->thread_id;
$state = $user->Option->getValue('creation_watch_state');
$watch = \XF::em()->create('XF:ThreadWatch');
$watch->thread_id = $threadid;
$watch->user_id = $userid;
$watch->email_subscribe = ($state == 'watch_email');
try
{
$watch->save();
}
catch (\XF\Db\DuplicateKeyException $e) {}
Everything appears to work correctly, and there is an entry in xf_thread_watch, but, when alerts are set to on, the user is not getting an alert.
However, if the user visits the thread (manually), and then somebody makes a post in it, an alert will appear without making any other changes.
It looks like alerts do not appear, because the user in who's name that thread was created, has not seen that thread. I do not believe this is normal behaviour.
Is there any way to programmatically make it look like the user has visited the thread at the same time the thread was made?
Thanks