From fe2dceb66d056809d9a145773a8053ac9fb02658 Mon Sep 17 00:00:00 2001
From: Wim Vanderbauwhede <Wim.Vanderbauwhede@mail.be>
Date: Fri, 4 Jan 2019 15:22:02 +0000
Subject: [PATCH 1/4] Patch to support image descriptions in Pleroma FE

---
 lib/pleroma/web/common_api/utils.ex | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 3ff9f9452..51e74ac8f 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -1,8 +1,9 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.CommonAPI.Utils do
+  require Logger
   alias Calendar.Strftime
   alias Comeonin.Pbkdf2
   alias Pleroma.{Activity, Formatter, Object, Repo}
@@ -32,9 +33,11 @@ def get_replied_to_activity(id) when not is_nil(id) do
 
   def get_replied_to_activity(_), do: nil
 
-  def attachments_from_ids(ids) do
-    Enum.map(ids || [], fn media_id ->
+  def attachments_from_ids(ids, descs) do
+    Enum.map(ids || [], fn media_id -> do
+      Logger.warn(descs[media_id])
       Repo.get(Object, media_id).data
+    end
     end)
   end
 

From 4c95545d194e8a807e9e3514ed75347d78ec0856 Mon Sep 17 00:00:00 2001
From: Wim Vanderbauwhede <Wim.Vanderbauwhede@mail.be>
Date: Fri, 4 Jan 2019 15:35:41 +0000
Subject: [PATCH 2/4] Patch to support image descriptions in Pleroma FE

---
 lib/pleroma/web/common_api/common_api.ex |  2 +-
 lib/pleroma/web/common_api/utils.ex      | 13 ++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index e474653ff..50074b8b0 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -90,7 +90,7 @@ def post(user, %{"status" => status} = data) do
     limit = Pleroma.Config.get([:instance, :limit])
 
     with status <- String.trim(status),
-         attachments <- attachments_from_ids(data["media_ids"]),
+         attachments <- attachments_from_ids(data["media_ids"], data["descriptions"]),
          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),
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 51e74ac8f..5fe21fb99 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -1,9 +1,8 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.CommonAPI.Utils do
-  require Logger
   alias Calendar.Strftime
   alias Comeonin.Pbkdf2
   alias Pleroma.{Activity, Formatter, Object, Repo}
@@ -33,11 +32,11 @@ def get_replied_to_activity(id) when not is_nil(id) do
 
   def get_replied_to_activity(_), do: nil
 
-  def attachments_from_ids(ids, descs) do
-    Enum.map(ids || [], fn media_id -> do
-      Logger.warn(descs[media_id])
-      Repo.get(Object, media_id).data
-    end
+  def attachments_from_ids(ids, descs_str) do
+    {_, descs} = Jason.decode(descs_str)
+
+    Enum.map(ids || [], fn media_id ->
+      Map.put(Repo.get(Object, media_id).data, "name", descs[media_id])
     end)
   end
 

From ba93396649f65a1f32eeedfd9ccd32cf308e7210 Mon Sep 17 00:00:00 2001
From: Wim Vanderbauwhede <Wim.Vanderbauwhede@mail.be>
Date: Fri, 4 Jan 2019 16:27:46 +0000
Subject: [PATCH 3/4] Patch to support image descriptions in Pleroma FE

---
 lib/pleroma/web/common_api/common_api.ex |  2 +-
 lib/pleroma/web/common_api/utils.ex      | 16 +++++++++++++++-
 priv/static/index.html                   |  2 +-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 50074b8b0..ef79b9c5d 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -90,7 +90,7 @@ def post(user, %{"status" => status} = data) 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),
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 5fe21fb99..59df48ed6 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -32,7 +32,21 @@ def get_replied_to_activity(id) when not is_nil(id) 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 ->
diff --git a/priv/static/index.html b/priv/static/index.html
index 83c11118c..068d2faec 100644
--- a/priv/static/index.html
+++ b/priv/static/index.html
@@ -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

From bf5b1c7f06c9f8882c40cf2385439bee3b74522c Mon Sep 17 00:00:00 2001
From: Wim Vanderbauwhede <Wim.Vanderbauwhede@mail.be>
Date: Sun, 20 Jan 2019 11:19:50 +0000
Subject: [PATCH 4/4] Removed file as requested

---
 priv/static/index.html | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 priv/static/index.html

diff --git a/priv/static/index.html b/priv/static/index.html
deleted file mode 100644
index 068d2faec..000000000
--- a/priv/static/index.html
+++ /dev/null
@@ -1 +0,0 @@
-<!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