Merge branch 'feature/article-support' into 'develop'
authorlambda <pleromagit@rogerbraun.net>
Thu, 12 Jul 2018 05:58:39 +0000 (05:58 +0000)
committerlambda <pleromagit@rogerbraun.net>
Thu, 12 Jul 2018 05:58:39 +0000 (05:58 +0000)
article support (plume, etc)

See merge request pleroma/pleroma!240

lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
lib/pleroma/web/twitter_api/representers/activity_representer.ex
lib/pleroma/web/twitter_api/views/activity_view.ex
test/web/twitter_api/representers/activity_representer_test.exs

index 30cd70fb656096df97ee86fe285d8fbe3a174dc3..59c4b90e7d89096aef27d3daaf4c5a0dd953df75 100644 (file)
@@ -122,7 +122,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   # TODO: validate those with a Ecto scheme
   # - tags
   # - emoji
-  def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
+  def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
+      when objtype in ["Article", "Note"] do
     with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
          %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
       object = fix_object(data["object"])
index 64329b710080362bbf6b4c30e8903e8efda00ff0..8b41a3becbb26cad7af645d8bd6480316bd2a8c0 100644 (file)
@@ -128,7 +128,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   Inserts a full object if it is contained in an activity.
   """
   def insert_full_object(%{"object" => %{"type" => type} = object_data})
-      when is_map(object_data) and type in ["Note"] do
+      when is_map(object_data) and type in ["Article", "Note"] do
     with {:ok, _} <- Object.create(object_data) do
       :ok
     end
index 39abb4c6b4cfc6951bbca5205c4252e7aed30c6a..4c20581d6239440f3e52b2a12ca9ee23f44d7d48 100644 (file)
@@ -127,7 +127,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       in_reply_to_id: reply_to && to_string(reply_to.id),
       in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
       reblog: nil,
-      content: HtmlSanitizeEx.basic_html(object["content"]),
+      content: render_content(object),
       created_at: created_at,
       reblogs_count: announcement_count,
       favourites_count: like_count,
@@ -206,4 +206,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         "direct"
     end
   end
+
+  def render_content(%{"type" => "Article"} = object) do
+    summary = object["name"]
+
+    content =
+      if !!summary and summary != "" do
+        "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
+      else
+        object["content"]
+      end
+
+    HtmlSanitizeEx.basic_html(content)
+  end
+
+  def render_content(object) do
+    HtmlSanitizeEx.basic_html(object["content"])
+  end
 end
index 57837205e08132f67efbf55b1dcc095a6a98c934..bb77e61f3ac854cde0e5604d0cdceca121340c2d 100644 (file)
@@ -4,7 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
   use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
   alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
   alias Pleroma.{Activity, User}
-  alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
+  alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
   alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.Formatter
 
@@ -164,14 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
 
     tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
 
-    summary = activity.data["object"]["summary"]
-
-    content =
-      if !!summary and summary != "" do
-        "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
-      else
-        content
-      end
+    {summary, content} = ActivityView.render_content(object)
 
     html =
       HtmlSanitizeEx.basic_html(content)
index 62ce3b7b5d0d152c1558099f13ee270f63ed68c0..f418249e2d616c9539b9f1ba115effcb93fac6ce 100644 (file)
@@ -228,15 +228,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
 
     tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
 
-    summary = activity.data["object"]["summary"]
-    content = object["content"]
-
-    content =
-      if !!summary and summary != "" do
-        "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
-      else
-        content
-      end
+    {summary, content} = render_content(object)
 
     html =
       HtmlSanitizeEx.basic_html(content)
@@ -266,4 +258,37 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
     }
   end
+
+  def render_content(%{"type" => "Note"} = object) do
+    summary = object["summary"]
+
+    content =
+      if !!summary and summary != "" do
+        "<p>#{summary}</p>#{object["content"]}"
+      else
+        object["content"]
+      end
+
+    {summary, content}
+  end
+
+  def render_content(%{"type" => "Article"} = object) do
+    summary = object["name"] || object["summary"]
+
+    content =
+      if !!summary and summary != "" do
+        "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
+      else
+        object["content"]
+      end
+
+    {summary, content}
+  end
+
+  def render_content(object) do
+    summary = object["summary"] || "Unhandled activity type: #{object["type"]}"
+    content = "<p>#{summary}</p>#{object["content"]}"
+
+    {summary, content}
+  end
 end
index 16c6e7b0d49f0551250b9fe380f8b422ff42909d..7505093dd2d4c93fab5d23fb7c1ad0fb2fd164a3 100644 (file)
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
     }
 
     expected_html =
-      "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
+      "<p>2hu</p>alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
         mentioned_user.ap_id
       }\">@shp</a>"