Extract mascot actions from MastodonAPIController to MascotController

This commit is contained in:
Egor Kislitsyn 2019-09-30 19:32:43 +07:00
commit 0c6009dd2e
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
5 changed files with 116 additions and 93 deletions

View file

@ -200,28 +200,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
def set_mascot(%{assigns: %{user: user}} = conn, %{"file" => file}) do
with {:ok, object} <- ActivityPub.upload(file, actor: User.ap_id(user)),
%{} = attachment_data <- Map.put(object.data, "id", object.id),
# Reject if not an image
%{type: "image"} = rendered <-
StatusView.render("attachment.json", %{attachment: attachment_data}) do
# Sure!
# Save to the user's info
{:ok, _user} = User.update_info(user, &User.Info.mascot_update(&1, rendered))
json(conn, rendered)
else
%{type: _} -> render_error(conn, :unsupported_media_type, "mascots can only be images")
end
end
def get_mascot(%{assigns: %{user: user}} = conn, _params) do
mascot = User.get_mascot(user)
json(conn, mascot)
end
def follows(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
with {_, %User{} = followed} <- {:followed, User.get_cached_by_nickname(uri)},
{_, true} <- {:followed, follower.id != followed.id},