Also show activities in OStatus.
[akkoma] / lib / pleroma / web / ostatus / ostatus_controller.ex
index ff6d7301ac977ea4cf0a6d20e8d874a92568fa20..fd8dcdf5237466f4178173e75c28acbfb8514405 100644 (file)
@@ -2,10 +2,16 @@ defmodule Pleroma.Web.OStatus.OStatusController do
   use Pleroma.Web, :controller
 
   alias Pleroma.{User, Activity}
-  alias Pleroma.Web.OStatus.FeedRepresenter
+  alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter}
   alias Pleroma.Repo
+  alias Pleroma.Web.{OStatus, Federator}
   import Ecto.Query
 
+  def feed_redirect(conn, %{"nickname" => nickname}) do
+    user = User.get_cached_by_nickname(nickname)
+    redirect conn, external: OStatus.feed_path(user)
+  end
+
   def feed(conn, %{"nickname" => nickname}) do
     user = User.get_cached_by_nickname(nickname)
     query = from activity in Activity,
@@ -16,8 +22,49 @@ defmodule Pleroma.Web.OStatus.OStatusController do
     activities = query
     |> Repo.all
 
-    response = FeedRepresenter.to_simple_form(user, activities, [user])
+    response = user
+    |> FeedRepresenter.to_simple_form(activities, [user])
+    |> :xmerl.export_simple(:xmerl_xml)
+    |> to_string
+
+    conn
+    |> put_resp_content_type("application/atom+xml")
+    |> send_resp(200, response)
+  end
+
+  def salmon_incoming(conn, params) do
+    {:ok, body, _conn} = read_body(conn)
+    {:ok, magic_key} = Pleroma.Web.Salmon.fetch_magic_key(body)
+    {:ok, doc} = Pleroma.Web.Salmon.decode_and_validate(magic_key, body)
+
+    Federator.enqueue(:incoming_doc, doc)
+
+    conn
+    |> send_resp(200, "")
+  end
+
+  def object(conn, %{"uuid" => uuid}) do
+    with id <- o_status_url(conn, :object, uuid),
+         %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
+         %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
+      represent_activity(conn, activity, user)
+    end
+  end
+
+  def activity(conn, %{"uuid" => uuid}) do
+    with id <- o_status_url(conn, :activity, uuid),
+         %Activity{} = activity <- Activity.get_by_ap_id(id),
+         %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
+      represent_activity(conn, activity, user)
+    end
+  end
+
+  defp represent_activity(conn, activity, user) do
+    response = activity
+    |> ActivityRepresenter.to_simple_form(user, true)
+    |> ActivityRepresenter.wrap_with_entry
     |> :xmerl.export_simple(:xmerl_xml)
+    |> to_string
 
     conn
     |> put_resp_content_type("application/atom+xml")