Patch to support image descriptions in Pleroma FE
[akkoma] / lib / pleroma / web / common_api / utils.ex
index 142283684b4d176448edd7605c8bae7eb7b79b0f..5fe21fb99c367d5f01ccbb3d51bf42b030c375a7 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.CommonAPI.Utils do
   alias Calendar.Strftime
   alias Comeonin.Pbkdf2
@@ -28,9 +32,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do
 
   def get_replied_to_activity(_), do: nil
 
-  def attachments_from_ids(ids) do
+  def attachments_from_ids(ids, descs_str) do
+    {_, descs} = Jason.decode(descs_str)
+
     Enum.map(ids || [], fn media_id ->
-      Repo.get(Object, media_id).data
+      Map.put(Repo.get(Object, media_id).data, "name", descs[media_id])
     end)
   end