philomena_web: hack in forum posts to the firehose (#2)

* philomena_web: hack in forum posts to the firehose

(cherry-picked from commit c5ff6f38f3c1274cd0c6160b798d6f74549735ef)
This commit is contained in:
Christine Dodrill 2020-07-04 13:13:05 -04:00 committed by byte[]
parent c65f27a1ff
commit 4cdc362237
3 changed files with 24 additions and 0 deletions

View file

@ -35,6 +35,14 @@ defmodule PhilomenaWeb.Topic.PostController do
Posts.reindex_post(post) Posts.reindex_post(post)
UserStatistics.inc_stat(conn.assigns.current_user, :forum_posts) 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 conn
|> put_flash(:info, "Post created successfully.") |> put_flash(:info, "Post created successfully.")
|> redirect( |> redirect(

View file

@ -108,6 +108,14 @@ defmodule PhilomenaWeb.TopicController do
Posts.reindex_post(post) Posts.reindex_post(post)
Topics.notify_topic(topic) 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 conn
|> put_flash(:info, "Successfully posted topic.") |> put_flash(:info, "Successfully posted topic.")
|> redirect(to: Routes.forum_topic_path(conn, :show, forum, topic)) |> redirect(to: Routes.forum_topic_path(conn, :show, forum, topic))

View file

@ -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)} %{post: render_one(post, PhilomenaWeb.Api.Json.Forum.Topic.PostView, "post.json", assigns)}
end 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 def render("post.json", %{post: %{topic: %{hidden_from_users: true}} = post}) do
%{ %{
id: post.id, id: post.id,