Don't add public recipient to notes that don't contain it.
authorRoger Braun <roger@rogerbraun.net>
Fri, 30 Jun 2017 13:54:32 +0000 (15:54 +0200)
committerRoger Braun <roger@rogerbraun.net>
Fri, 30 Jun 2017 13:54:32 +0000 (15:54 +0200)
lib/pleroma/web/ostatus/handlers/note_handler.ex
test/fixtures/dm.xml [new file with mode: 0644]

index 82e60676f18c28851d464478216ee60e5bd12441..e0e4afef690f6283d5a69c996692e441cdd16e35 100644 (file)
@@ -37,14 +37,30 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
     end
   end
 
-  def get_mentions(entry) do
+  def get_people_mentions(entry) do
     :xmerl_xpath.string('//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/person"]', entry)
     |> Enum.map(fn(person) -> XML.string_from_xpath("@href", person) end)
   end
 
+  def get_collection_mentions(entry) do
+    transmogrify = fn
+      ("http://activityschema.org/collection/public") ->
+        "https://www.w3.org/ns/activitystreams#Public"
+      (group) ->
+        group
+    end
+
+    :xmerl_xpath.string('//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/collection"]', entry)
+    |> Enum.map(fn(collection) -> XML.string_from_xpath("@href", collection) |> transmogrify.() end)
+  end
+
+  def get_mentions(entry) do
+    get_people_mentions(entry)
+    ++ get_collection_mentions(entry)
+  end
+
   def make_to_list(actor, mentions) do
     [
-      "https://www.w3.org/ns/activitystreams#Public",
       User.ap_followers(actor)
     ] ++ mentions
   end
diff --git a/test/fixtures/dm.xml b/test/fixtures/dm.xml
new file mode 100644 (file)
index 0000000..d0b8aa8
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
+  <id>tag:mastodon.social,2017-06-30:objectId=11260427:objectType=Status</id>
+  <published>2017-06-30T13:27:47Z</published>
+  <updated>2017-06-30T13:27:47Z</updated>
+  <title>New status by lambadalambda</title>
+  <author>
+    <id>https://mastodon.social/users/lambadalambda</id>
+    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+    <uri>https://mastodon.social/users/lambadalambda</uri>
+    <name>lambadalambda</name>
+    <email>lambadalambda@mastodon.social</email>
+    <link rel="alternate" type="text/html" href="https://mastodon.social/@lambadalambda"/>
+    <link rel="avatar" type="image/gif" media:width="120" media:height="120" href="https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif"/>
+    <poco:preferredUsername>lambadalambda</poco:preferredUsername>
+    <poco:displayName>Critical Value</poco:displayName>
+    <mastodon:scope>public</mastodon:scope>
+  </author>
+  <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
+  <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
+  <content type="html" xml:lang="ky">&lt;p&gt;&lt;span class="h-card"&gt;&lt;a href="https://pleroma.soykaf.com/users/lain" class="u-url mention"&gt;@&lt;span&gt;lain&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; Hey.&lt;/p&gt;</content>
+  <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://pleroma.soykaf.com/users/lain"/>
+  <mastodon:scope>direct</mastodon:scope>
+  <link rel="alternate" type="text/html" href="https://mastodon.social/users/lambadalambda/updates/3514345"/>
+  <link rel="self" type="application/atom+xml" href="https://mastodon.social/users/lambadalambda/updates/3514345.atom"/>
+  <ostatus:conversation ref="tag:mastodon.social,2017-06-30:objectId=4009714:objectType=Conversation"/>
+</entry>