Merge branch 'hj-happiness-improvement' into 'develop'
[akkoma] / lib / pleroma / web / mastodon_api / mastodon_api_controller.ex
index 4c5f1e7a9aee11a7de823efd1092148f6b04c89a..65b61202624a2bb76bb4ac9862074960901516ab 100644 (file)
@@ -499,7 +499,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def upload(%{assigns: %{user: user}} = conn, %{"file" => file} = data) do
     with {:ok, object} <-
-           ActivityPub.upload(file,
+           ActivityPub.upload(
+             file,
              actor: User.ap_id(user),
              description: Map.get(data, "description")
            ) do
@@ -541,7 +542,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     local_only = params["local"] in [true, "True", "true", "1"]
 
     tags =
-      ([params["tag"]] ++ (params["any"] || []))
+      [params["tag"], params["any"]]
+      |> List.flatten()
       |> Enum.uniq()
       |> Enum.filter(& &1)
       |> Enum.map(&String.downcase(&1))
@@ -1099,7 +1101,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   def login(conn, _) do
     with {:ok, app} <- get_or_make_app() do
       path =
-        o_auth_path(conn, :authorize,
+        o_auth_path(
+          conn,
+          :authorize,
           response_type: "code",
           client_id: app.client_id,
           redirect_uri: ".",
@@ -1340,6 +1344,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     end
   end
 
+  def status_card(conn, %{"id" => status_id}) do
+    with %Activity{} = activity <- Repo.get(Activity, status_id),
+         true <- ActivityPub.is_public?(activity) do
+      data =
+        StatusView.render(
+          "card.json",
+          Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+        )
+
+      json(conn, data)
+    else
+      _e ->
+        %{}
+    end
+  end
+
   def try_render(conn, target, params)
       when is_binary(target) do
     res = render(conn, target, params)