Merge branch 'mastoapi/plaintext-statuses' into 'develop'
Provide plaintext representations of content/cw in MastoAPI Closes #787 See merge request pleroma/pleroma!1035
This commit is contained in:
commit
144648de92
|
@ -20,6 +20,8 @@ Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
- `local`: true if the post was made on the local instance.
|
- `local`: true if the post was made on the local instance.
|
||||||
- `conversation_id`: the ID of the conversation the status is associated with (if any)
|
- `conversation_id`: the ID of the conversation the status is associated with (if any)
|
||||||
|
- `content`: a map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
||||||
|
- `spoiler_text`: a map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
||||||
|
|
||||||
## Attachments
|
## Attachments
|
||||||
|
|
||||||
|
|
|
@ -147,20 +147,39 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
content =
|
content =
|
||||||
object
|
object
|
||||||
|> render_content()
|
|> render_content()
|
||||||
|
|
||||||
|
content_html =
|
||||||
|
content
|
||||||
|> HTML.get_cached_scrubbed_html_for_activity(
|
|> HTML.get_cached_scrubbed_html_for_activity(
|
||||||
User.html_filter_policy(opts[:for]),
|
User.html_filter_policy(opts[:for]),
|
||||||
activity,
|
activity,
|
||||||
"mastoapi:content"
|
"mastoapi:content"
|
||||||
)
|
)
|
||||||
|
|
||||||
summary =
|
content_plaintext =
|
||||||
(object["summary"] || "")
|
content
|
||||||
|
|> HTML.get_cached_stripped_html_for_activity(
|
||||||
|
activity,
|
||||||
|
"mastoapi:content"
|
||||||
|
)
|
||||||
|
|
||||||
|
summary = object["summary"] || ""
|
||||||
|
|
||||||
|
summary_html =
|
||||||
|
summary
|
||||||
|> HTML.get_cached_scrubbed_html_for_activity(
|
|> HTML.get_cached_scrubbed_html_for_activity(
|
||||||
User.html_filter_policy(opts[:for]),
|
User.html_filter_policy(opts[:for]),
|
||||||
activity,
|
activity,
|
||||||
"mastoapi:summary"
|
"mastoapi:summary"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
summary_plaintext =
|
||||||
|
summary
|
||||||
|
|> HTML.get_cached_stripped_html_for_activity(
|
||||||
|
activity,
|
||||||
|
"mastoapi:summary"
|
||||||
|
)
|
||||||
|
|
||||||
card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity))
|
card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity))
|
||||||
|
|
||||||
url =
|
url =
|
||||||
|
@ -179,7 +198,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
|
in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
|
||||||
reblog: nil,
|
reblog: nil,
|
||||||
card: card,
|
card: card,
|
||||||
content: content,
|
content: content_html,
|
||||||
created_at: created_at,
|
created_at: created_at,
|
||||||
reblogs_count: announcement_count,
|
reblogs_count: announcement_count,
|
||||||
replies_count: object["repliesCount"] || 0,
|
replies_count: object["repliesCount"] || 0,
|
||||||
|
@ -190,7 +209,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),
|
muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),
|
||||||
pinned: pinned?(activity, user),
|
pinned: pinned?(activity, user),
|
||||||
sensitive: sensitive,
|
sensitive: sensitive,
|
||||||
spoiler_text: summary,
|
spoiler_text: summary_html,
|
||||||
visibility: get_visibility(object),
|
visibility: get_visibility(object),
|
||||||
media_attachments: attachments,
|
media_attachments: attachments,
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
|
@ -203,7 +222,9 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
emojis: build_emojis(activity.data["object"]["emoji"]),
|
emojis: build_emojis(activity.data["object"]["emoji"]),
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
local: activity.local,
|
local: activity.local,
|
||||||
conversation_id: get_context_id(activity)
|
conversation_id: get_context_id(activity),
|
||||||
|
content: %{"text/plain" => content_plaintext},
|
||||||
|
spoiler_text: %{"text/plain" => summary_plaintext}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,7 +101,7 @@ test "a note activity" do
|
||||||
muted: false,
|
muted: false,
|
||||||
pinned: false,
|
pinned: false,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
spoiler_text: note.data["object"]["summary"],
|
spoiler_text: HtmlSanitizeEx.basic_html(note.data["object"]["summary"]),
|
||||||
visibility: "public",
|
visibility: "public",
|
||||||
media_attachments: [],
|
media_attachments: [],
|
||||||
mentions: [],
|
mentions: [],
|
||||||
|
@ -126,7 +126,9 @@ test "a note activity" do
|
||||||
],
|
],
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
local: true,
|
local: true,
|
||||||
conversation_id: convo_id
|
conversation_id: convo_id,
|
||||||
|
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["content"])},
|
||||||
|
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["summary"])}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue