Wire up mentions.
[akkoma] / lib / pleroma / web / ostatus / ostatus.ex
index 4fd649c92093575e6ba83e6abf1979ae2d6be122..65141f8263042561ae8633246bc5281a0f1eb668 100644 (file)
@@ -31,22 +31,29 @@ defmodule Pleroma.Web.OStatus do
   end
 
   # TODO
-  # Parse mention
   # wire up replies
-  # Set correct context
-  # Set correct statusnet ids.
   def handle_note(doc) do
     content_html = string_from_xpath("/entry/content[1]", doc)
 
     [author] = :xmerl_xpath.string('/entry/author[1]', doc)
     {:ok, actor} = find_or_make_user(author)
 
-    context = ActivityPub.generate_context_id
+    context = string_from_xpath("/entry/ostatus:conversation[1]", doc) |> String.trim
+    context = if String.length(context) > 0 do
+      context
+    else
+      ActivityPub.generate_context_id
+    end
 
     to = [
       "https://www.w3.org/ns/activitystreams#Public"
     ]
 
+    mentions = :xmerl_xpath.string('/entry/link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/person"]', doc)
+    |> Enum.map(fn(person) -> string_from_xpath("@href", person) end)
+
+    to = to ++ mentions
+
     date = string_from_xpath("/entry/published", doc)
 
     object = %{
@@ -61,19 +68,6 @@ defmodule Pleroma.Web.OStatus do
     ActivityPub.create(to, actor, context, object, %{}, date)
   end
 
-  def find_or_make(author, doc) do
-    query = from user in User,
-      where: user.local == false and fragment("? @> ?", user.info, ^%{ostatus_uri: author})
-
-    user = Repo.one(query)
-
-    if is_nil(user) do
-      make_user(doc)
-    else
-      {:ok, user}
-    end
-  end
-
   def find_or_make_user(author_doc) do
     {:xmlObj, :string, uri } = :xmerl_xpath.string('string(/author[1]/uri)', author_doc)