Save cws in the activitypub data.

This commit is contained in:
Roger Braun 2017-10-31 17:30:46 +01:00
parent 4dcbb64f19
commit 4cbf17dac6
4 changed files with 15 additions and 9 deletions

View File

@ -94,11 +94,12 @@ def add_user_links(text, mentions) do
end) end)
end end
def make_note_data(actor, to, context, content_html, attachments, inReplyTo, tags) do def make_note_data(actor, to, context, content_html, attachments, inReplyTo, tags, cw \\ nil) do
object = %{ object = %{
"type" => "Note", "type" => "Note",
"to" => to, "to" => to,
"content" => content_html, "content" => content_html,
"summary" => cw,
"context" => context, "context" => context,
"attachment" => attachments, "attachment" => attachments,
"actor" => actor, "actor" => actor,

View File

@ -94,6 +94,7 @@ def handle_note(entry, doc \\ nil) do
[author] <- :xmerl_xpath.string('//author[1]', doc), [author] <- :xmerl_xpath.string('//author[1]', doc),
{:ok, actor} <- OStatus.find_make_or_update_user(author), {:ok, actor} <- OStatus.find_make_or_update_user(author),
content_html <- OStatus.get_content(entry), content_html <- OStatus.get_content(entry),
cw <- OStatus.get_cw(entry),
inReplyTo <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry), inReplyTo <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry),
inReplyToActivity <- fetch_replied_to_activity(entry, inReplyTo), inReplyToActivity <- fetch_replied_to_activity(entry, inReplyTo),
inReplyTo <- (inReplyToActivity && inReplyToActivity.data["object"]["id"]) || inReplyTo, inReplyTo <- (inReplyToActivity && inReplyToActivity.data["object"]["id"]) || inReplyTo,
@ -103,7 +104,7 @@ def handle_note(entry, doc \\ nil) do
mentions <- get_mentions(entry), mentions <- get_mentions(entry),
to <- make_to_list(actor, mentions), to <- make_to_list(actor, mentions),
date <- XML.string_from_xpath("//published", entry), date <- XML.string_from_xpath("//published", entry),
note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, []), note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, [], cw),
note <- note |> Map.put("id", id) |> Map.put("tag", tags), note <- note |> Map.put("id", id) |> Map.put("tag", tags),
note <- note |> Map.put("published", date), note <- note |> Map.put("published", date),
note <- note |> Map.put("emoji", get_emoji(entry)), note <- note |> Map.put("emoji", get_emoji(entry)),

View File

@ -150,16 +150,20 @@ def get_attachments(entry) do
end end
@doc """ @doc """
Gets the content from a an entry. Will add the cw text to the body for cw'd Gets the content from a an entry.
Mastodon notes.
""" """
def get_content(entry) do def get_content(entry) do
base_content = string_from_xpath("//content", entry) string_from_xpath("//content", entry)
end
@doc """
Get the cw that mastodon uses.
"""
def get_cw(entry) do
with scope when not is_nil(scope) <- string_from_xpath("//mastodon:scope", entry), with scope when not is_nil(scope) <- string_from_xpath("//mastodon:scope", entry),
cw when not is_nil(cw) <- string_from_xpath("/*/summary", entry) do cw when not is_nil(cw) <- string_from_xpath("/*/summary", entry) do
"<span class='mastodon-cw'>#{cw}</span><br>#{base_content}" cw
else _e -> base_content else _e -> nil
end end
end end

View File

@ -85,7 +85,7 @@ test "handle incoming notes - Mastodon, with CW" do
assert activity.data["type"] == "Create" assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda" assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
assert String.contains?(activity.data["object"]["content"], "technologic") assert activity.data["object"]["summary"] == "technologic"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end end
@ -93,7 +93,7 @@ test "handle incoming retweets - Mastodon, with CW" do
incoming = File.read!("test/fixtures/cw_retweet.xml") incoming = File.read!("test/fixtures/cw_retweet.xml")
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.") assert retweeted_activity.data["object"]["summary"] == "Hey."
end end
test "handle incoming notes - GS, subscription, reply" do test "handle incoming notes - GS, subscription, reply" do