add additional live events

This commit is contained in:
byte[] 2020-06-15 19:57:33 -04:00
parent e38ea68260
commit cec8b605a8
6 changed files with 41 additions and 1 deletions

View file

@ -3,5 +3,11 @@ defmodule Philomena.ThumbnailWorker do
def perform(image_id) do
Thumbnailer.generate_thumbnails(image_id)
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:processed",
%{image_id: image_id}
)
end
end

View file

@ -41,6 +41,12 @@ defmodule PhilomenaWeb.Api.Json.ImageController do
case Images.create_image(attributes, image_params) do
{:ok, %{image: image}} ->
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:create",
PhilomenaWeb.Api.Json.ImageView.render("show.json", %{image: image, interactions: []})
)
render(conn, "show.json", image: image, interactions: [])
{:error, :image, changeset, _} ->

View file

@ -103,6 +103,12 @@ defmodule PhilomenaWeb.Image.CommentController do
def update(conn, %{"comment" => comment_params}) do
case Comments.update_comment(conn.assigns.comment, conn.assigns.current_user, comment_params) do
{:ok, %{comment: comment}} ->
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"comment:update",
PhilomenaWeb.Api.Json.CommentView.render("show.json", %{comment: comment})
)
Comments.reindex_comment(comment)
conn

View file

@ -7,13 +7,25 @@ defmodule PhilomenaWeb.Image.DescriptionController do
plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.CanaryMapPlug, update: :edit_description
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true, preload: [:tags, :user]
def update(conn, %{"image" => image_params}) do
image = conn.assigns.image
old_description = image.description
case Images.update_description(image, image_params) do
{:ok, image} ->
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:description_update",
%{image_id: image.id, added: image.description, removed: old_description}
)
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:update",
PhilomenaWeb.Api.Json.ImageView.render("show.json", %{image: image, interactions: []})
)
Images.reindex_image(image)
body = TextileRenderer.render_one(%{body: image.description}, conn)

View file

@ -21,6 +21,11 @@ defmodule PhilomenaWeb.Image.SourceController do
case Images.update_source(image, attributes, image_params) do
{:ok, %{image: image}} ->
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:source_update",
%{image_id: image.id, added: [image.source_url], removed: [old_source]}
)
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:update",

View file

@ -22,6 +22,11 @@ defmodule PhilomenaWeb.Image.TagController do
case Images.update_tags(image, attributes, image_params) do
{:ok, %{image: {image, added_tags, removed_tags}}} ->
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:tag_update",
%{image_id: image.id, added: Enum.map(added_tags, & &1.name), removed: Enum.map(removed_tags, & &1.name)}
)
PhilomenaWeb.Endpoint.broadcast!(
"firehose",
"image:update",