diff options
author | William Pitcock <nenolod@dereferenced.org> | 2018-06-24 05:33:34 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2018-06-27 13:37:53 +0000 |
commit | 121c1f62306e416f1f6106d1751b55a5eb9f9075 (patch) | |
tree | 343a025c1c4376977ca7e578481a706f52200135 | |
parent | bd479606ba2b645db46ef5312f06323534cfd9c9 (diff) | |
download | pleroma-121c1f62306e416f1f6106d1751b55a5eb9f9075.tar.gz pleroma-121c1f62306e416f1f6106d1751b55a5eb9f9075.zip |
twitter api: refactor activity html generation, add support for Articles
-rw-r--r-- | lib/pleroma/web/twitter_api/views/activity_view.ex | 41 |
1 files 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 - "<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,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 + "<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 |