Hello,
I'm developing an extension, and I want it to automatically send a private message to users using the "fof/byobu" extension when a new post is added to a specific discussion. I've tried different approaches, but I couldn't create the discussion as private. It doesn't function exactly like a private message. Below is the relevant code snippet. I'm new to Flarum, so I'm not entirely sure if I'm following the correct approach.
$admin = User::find(1);
// Create Discussion
$discussion = new Discussion();
$discussion->title = 'New Discussion Title';
$discussion->user_id = $admin->id;
$discussion->created_at = time();
$discussion->save();
// Create Post
$newPost = new CommentPost();
$newPost->discussion_id = $discussion->id;
$newPost->user_id = $admin->id;
$newPost->content = 'Hello, your request has been received. If you have any questions, you can contact us here.';
$newPost->created_at = time();
$newPost->number = 1;
$newPost->is_private = true;
$newPost->save();
// Set discussion start post ID
$discussion->first_post_id = $newPost->id;
$discussion->last_posted_user_id = $admin->id;
$discussion->last_post_id = $newPost->id;
$discussion->last_post_number = 1;
$discussion->is_private = true;
$discussion->save();
I create the discussion without any errors using this code. However, even though I set is_private
to true or 1 in the code, it doesn't get saved as private in the database.
I'm using the CommentPost
class instead of the Post
class because I couldn't find a way to set the post type in the Post
class.
Thank you.