Patch to support image descriptions in Pleroma FE
authorWim Vanderbauwhede <Wim.Vanderbauwhede@mail.be>
Fri, 4 Jan 2019 16:27:46 +0000 (16:27 +0000)
committerWim Vanderbauwhede <Wim.Vanderbauwhede@mail.be>
Fri, 4 Jan 2019 16:27:46 +0000 (16:27 +0000)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/utils.ex
priv/static/index.html

index 50074b8b00174d741a1627dc26ab4229208de05b..ef79b9c5d4a038f4a4797dffbf03b862d4b0a98a 100644 (file)
@@ -90,7 +90,7 @@ defmodule Pleroma.Web.CommonAPI do
     limit = Pleroma.Config.get([:instance, :limit])
 
     with status <- String.trim(status),
-         attachments <- attachments_from_ids(data["media_ids"], data["descriptions"]),
+         attachments <- attachments_from_ids(data),
          mentions <- Formatter.parse_mentions(status),
          inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]),
          {to, cc} <- to_for_user_and_mentions(user, mentions, inReplyTo, visibility),
index 5fe21fb99c367d5f01ccbb3d51bf42b030c375a7..59df48ed638598efa25bf1194925c7b4df10d4ee 100644 (file)
@@ -32,7 +32,21 @@ defmodule Pleroma.Web.CommonAPI.Utils do
 
   def get_replied_to_activity(_), do: nil
 
-  def attachments_from_ids(ids, descs_str) do
+  def attachments_from_ids(data) do
+    if Map.has_key?(data, "descriptions") do
+      attachments_from_ids_descs(data["media_ids"], data["descriptions"])
+    else
+      attachments_from_ids_no_descs(data["media_ids"])
+    end
+  end
+
+  def attachments_from_ids_no_descs(ids) do
+    Enum.map(ids || [], fn media_id ->
+      Repo.get(Object, media_id).data
+    end)
+  end
+
+  def attachments_from_ids_descs(ids, descs_str) do
     {_, descs} = Jason.decode(descs_str)
 
     Enum.map(ids || [], fn media_id ->
index 83c11118c992b7e9bd7bf89af0d25e493706b737..068d2faec00d05e3e3083aec70db1dc06a818ab1 100644 (file)
@@ -1 +1 @@
-<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link rel=stylesheet href=/static/font/css/fontello.css><link rel=stylesheet href=/static/font/css/animation.css><link href=/static/css/app.c52cbb57296d5c682ff405d562e83a9b.css rel=stylesheet></head><body style="display: none"><div id=app></div><script type=text/javascript src=/static/js/manifest.e833e1c75fbc9f2b69b4.js></script><script type=text/javascript src=/static/js/vendor.b6e63c523d95d763c254.js></script><script type=text/javascript src=/static/js/app.1c83eacd8eddeef56c69.js></script></body></html>
\ No newline at end of file
+<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link rel=stylesheet href=/static/font/css/fontello.css><link rel=stylesheet href=/static/font/css/animation.css><link href=/static/css/app.b1d1f344ad9db7641c9301646fbf84f7.css rel=stylesheet></head><body style="display: none"><div id=app></div><script type=text/javascript src=/static/js/manifest.2004a2a8c0c0ff8b88bb.js></script><script type=text/javascript src=/static/js/vendor.99461187584bc80acda1.js></script><script type=text/javascript src=/static/js/app.161b20a2134c1c792154.js></script></body></html>
\ No newline at end of file