diff --git a/lib/philomena_web/controllers/topic/post_controller.ex b/lib/philomena_web/controllers/topic/post_controller.ex index f1234dc3..df6b62c1 100644 --- a/lib/philomena_web/controllers/topic/post_controller.ex +++ b/lib/philomena_web/controllers/topic/post_controller.ex @@ -35,6 +35,14 @@ defmodule PhilomenaWeb.Topic.PostController do Posts.reindex_post(post) UserStatistics.inc_stat(conn.assigns.current_user, :forum_posts) + if forum.access_level == "normal" do + PhilomenaWeb.Endpoint.broadcast!( + "firehose", + "post:create", + PhilomenaWeb.Api.Json.Forum.Topic.PostView.render("firehose.json", %{post: post, topic: topic, forum: forum}) + ) + end + conn |> put_flash(:info, "Post created successfully.") |> redirect( diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index e96ab7ad..9d781676 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -108,6 +108,14 @@ defmodule PhilomenaWeb.TopicController do Posts.reindex_post(post) Topics.notify_topic(topic) + if forum.access_level == "normal" do + PhilomenaWeb.Endpoint.broadcast!( + "firehose", + "post:create", + PhilomenaWeb.Api.Json.Forum.Topic.PostView.render("firehose.json", %{post: post, topic: topic, forum: forum}) + ) + end + conn |> put_flash(:info, "Successfully posted topic.") |> redirect(to: Routes.forum_topic_path(conn, :show, forum, topic)) diff --git a/lib/philomena_web/views/api/json/forum/topic/post_view.ex b/lib/philomena_web/views/api/json/forum/topic/post_view.ex index ef69e3d6..4d6ecdcb 100644 --- a/lib/philomena_web/views/api/json/forum/topic/post_view.ex +++ b/lib/philomena_web/views/api/json/forum/topic/post_view.ex @@ -13,6 +13,14 @@ defmodule PhilomenaWeb.Api.Json.Forum.Topic.PostView do %{post: render_one(post, PhilomenaWeb.Api.Json.Forum.Topic.PostView, "post.json", assigns)} end + def render("firehose.json", %{post: post, topic: topic, forum: forum} = assigns) do + %{ + post: render_one(post, PhilomenaWeb.Api.Json.Forum.Topic.PostView, "post.json", assigns), + topic: render_one(topic, PhilomenaWeb.Api.Json.Forum.TopicView, "topic.json", assigns), + forum: render_one(forum, PhilomenaWeb.Api.Json.ForumView, "forum.json", assigns) + } + end + def render("post.json", %{post: %{topic: %{hidden_from_users: true}} = post}) do %{ id: post.id,