From c42f28b82c01423d05b85514797bf3bce692628d Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 05:33:22 +0000
Subject: [PATCH 1/6] transmogrifier: accept Article activities
---
lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 30cd70fb6..1b60170d9 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -122,7 +122,7 @@ 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"])
From bd479606ba2b645db46ef5312f06323534cfd9c9 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:52:17 +0000
Subject: [PATCH 2/6] utils: make_create_data: add support for Article objects
---
lib/pleroma/web/activity_pub/utils.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 64329b710..8b41a3bec 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -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
From 121c1f62306e416f1f6106d1751b55a5eb9f9075 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 05:33:34 +0000
Subject: [PATCH 3/6] twitter api: refactor activity html generation, add
support for Articles
---
lib/pleroma/web/twitter_api/views/activity_view.ex | 41 +++++++++++++++++-----
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 62ce3b7b5..0779872fe 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -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
- "#{activity.data["object"]["summary"]}
#{content}"
- else
- content
- end
+ {summary, content} = render_content(object)
html =
HtmlSanitizeEx.basic_html(content)
@@ -266,4 +258,35 @@ 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
+ "#{summary}
#{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
+ "#{summary}
#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ {summary, content}
+ end
+
+ def render_content(object) do
+ summary = object["summary"] || "Unhandled activity type: #{object["type"]}"
+ content = "#{summary}
#{object["content"]}"
+
+ {summary, content}
+ end
end
From ea982e7503767f645dc26235e04c541ce976de71 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:14:17 +0000
Subject: [PATCH 4/6] mastodon api: add interpreter for Article activity types
---
lib/pleroma/web/mastodon_api/views/status_view.ex | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 59898457b..f7ad87bad 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -128,7 +128,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,
@@ -207,4 +207,20 @@ 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
+ "#{summary}
#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ HtmlSanitizeEx.basic_html(content)
+ end
+
+ def render_content(object) do
+ HtmlSanitizeEx.basic_html(object["content"])
+ end
end
From 66819ea784509fbed3f7db8056ececf150339b35 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:30:23 +0000
Subject: [PATCH 5/6] twitter api: use ActivityView.render_content() where
appropriate instead of duplicating the logic
---
.../web/twitter_api/representers/activity_representer.ex | 11 ++---------
.../twitter_api/representers/activity_representer_test.exs | 2 +-
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
index 57837205e..bb77e61f3 100644
--- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex
+++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
@@ -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
- "#{activity.data["object"]["summary"]}
#{content}"
- else
- content
- end
+ {summary, content} = ActivityView.render_content(object)
html =
HtmlSanitizeEx.basic_html(content)
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 16c6e7b0d..7505093dd 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}
expected_html =
- "2hu
alert('YAY')Some content mentioning 2hu
alert('YAY')Some content mentioning @shp"
From 971bb4f2bde125c1f8397c244a6fbdec0d26716b Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Jun 2018 06:34:44 +0000
Subject: [PATCH 6/6] activity interpretation: formatting
---
lib/pleroma/web/activity_pub/transmogrifier.ex | 3 ++-
lib/pleroma/web/mastodon_api/views/status_view.ex | 1 +
lib/pleroma/web/twitter_api/views/activity_view.ex | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 1b60170d9..59c4b90e7 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -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" => objtype} = object} = data) when objtype in ["Article", "Note"] 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"])
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index f7ad87bad..6b48c41c1 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -210,6 +210,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render_content(%{"type" => "Article"} = object) do
summary = object["name"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 0779872fe..f418249e2 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -261,6 +261,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Note"} = object) do
summary = object["summary"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"
@@ -273,6 +274,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render_content(%{"type" => "Article"} = object) do
summary = object["name"] || object["summary"]
+
content =
if !!summary and summary != "" do
"#{summary}
#{object["content"]}"