From beb7b0ef07f880b6eecc01d04980b38ba8521a81 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 18 May 2017 15:58:18 +0200 Subject: [PATCH] Handle incoming tags. --- lib/pleroma/web/ostatus/ostatus.ex | 10 +++- test/fixtures/ostatus_incoming_post_tag.xml | 58 +++++++++++++++++++++ test/web/ostatus/ostatus_test.exs | 7 +++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/ostatus_incoming_post_tag.xml diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 949b36664..e913e389f 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -133,6 +133,11 @@ def get_content(entry) do end end + def get_tags(entry) do + :xmerl_xpath.string('//category', entry) + |> Enum.map(fn (category) -> string_from_xpath("/category/@term", category) end) + end + def handle_note(entry, doc \\ nil) do content_html = get_content(entry) @@ -163,6 +168,8 @@ def handle_note(entry, doc \\ nil) do end end + tags = get_tags(entry) + to = [ "https://www.w3.org/ns/activitystreams#Public", User.ap_followers(actor) @@ -184,7 +191,8 @@ def handle_note(entry, doc \\ nil) do "published" => date, "context" => context, "actor" => actor.ap_id, - "attachment" => attachments + "attachment" => attachments, + "tag" => tags } object = if inReplyTo do diff --git a/test/fixtures/ostatus_incoming_post_tag.xml b/test/fixtures/ostatus_incoming_post_tag.xml new file mode 100644 index 000000000..695766d73 --- /dev/null +++ b/test/fixtures/ostatus_incoming_post_tag.xml @@ -0,0 +1,58 @@ + + + GNU social + https://social.heldscal.la/api/statuses/user_timeline/23211.atom + lambadalambda timeline + Updates from lambadalambda on social.heldscal.la! + https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg + 2017-04-29T18:25:38+00:00 + + http://activitystrea.ms/schema/1.0/person + https://social.heldscal.la/user/23211 + lambadalambda + Call me Deacon Blues. + + + + + + lambadalambda + Constance Variable + Call me Deacon Blues. + + Berlin + + + homepage + https://heldscal.la + true + + + + + + + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:social.heldscal.la,2017-04-29:noticeId=1967725:objectType=note + New note by lambadalambda + Will it blend? + + + + http://activitystrea.ms/schema/1.0/post + 2017-04-29T18:25:38+00:00 + 2017-04-29T18:25:38+00:00 + + tag:social.heldscal.la,2017-04-29:objectType=thread:nonce=3f3a9dd83acc4e35 + + + + + + diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index e38a195d9..6599b00b3 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -46,6 +46,13 @@ test "handle incoming notes with attachments - GS, subscription" do assert activity.data["object"]["attachment"] |> length == 2 end + test "handle incoming notes with tags" do + incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["object"]["tag"] == ["nsfw"] + end + test "handle incoming notes - Mastodon, salmon, reply" do # It uses the context of the replied to object Repo.insert!(%Object{