mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
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:
parent
c65f27a1ff
commit
4cdc362237
3 changed files with 24 additions and 0 deletions
|
@ -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(
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue