Output proper published data in ostatus.
[akkoma] / lib / pleroma / web / ostatus / ostatus.ex
index 949b36664d921722ce08d0894afa84ce41cfd36b..02fc273cf7eabecfc23a5a1a54c1b23d64bfed75 100644 (file)
@@ -63,8 +63,7 @@ defmodule Pleroma.Web.OStatus do
   end
 
   def handle_share(entry, doc) do
-    with [object] <- :xmerl_xpath.string('/entry/activity:object', entry),
-         {:ok, retweeted_activity} <-  handle_note(object, object),
+    with {:ok, retweeted_activity} <- get_or_build_object(entry),
          {:ok, activity} <- make_share(entry, doc, retweeted_activity) do
       {:ok, activity, retweeted_activity}
     else
@@ -81,6 +80,18 @@ defmodule Pleroma.Web.OStatus do
     end
   end
 
+  def get_or_build_object(entry) do
+    with {:ok, activity} <- get_or_try_fetching(entry) do
+      {:ok, activity}
+    else
+      _e ->
+        with [object] <- :xmerl_xpath.string('/entry/activity:object', entry) do
+          handle_note(object, object)
+        end
+    end
+  end
+
+
   def get_or_try_fetching(entry) do
     Logger.debug("Trying to get entry from db")
     with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry),
@@ -133,6 +144,11 @@ defmodule Pleroma.Web.OStatus 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 +179,8 @@ defmodule Pleroma.Web.OStatus do
                 end
               end
 
+    tags = get_tags(entry)
+
     to = [
       "https://www.w3.org/ns/activitystreams#Public",
       User.ap_followers(actor)
@@ -184,11 +202,20 @@ defmodule Pleroma.Web.OStatus do
       "published" => date,
       "context" => context,
       "actor" => actor.ap_id,
-      "attachment" => attachments
+      "attachment" => attachments,
+      "tag" => tags
     }
 
     object = if inReplyTo do
-      Map.put(object, "inReplyTo", inReplyTo)
+      replied_to_activity = Activity.get_create_activity_by_object_ap_id(inReplyTo)
+      if replied_to_activity do
+        object
+        |> Map.put("inReplyTo", inReplyTo)
+        |> Map.put("inReplyToStatusId", replied_to_activity.id)
+      else
+        object
+        |> Map.put("inReplyTo", inReplyTo)
+      end
     else
       object
     end