1 defmodule Pleroma.Web.OStatus.OStatusController do
2 use Pleroma.Web, :controller
4 alias Pleroma.{User, Activity}
5 alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter}
7 alias Pleroma.Web.{OStatus, Federator}
10 def feed_redirect(conn, %{"nickname" => nickname}) do
11 user = User.get_cached_by_nickname(nickname)
13 case get_format(conn) do
14 "html" -> Fallback.RedirectController.redirector(conn, nil)
15 _ -> redirect conn, external: OStatus.feed_path(user)
19 def feed(conn, %{"nickname" => nickname}) do
20 user = User.get_cached_by_nickname(nickname)
21 query = from activity in Activity,
22 where: fragment("?->>'actor' = ?", activity.data, ^user.ap_id),
30 |> FeedRepresenter.to_simple_form(activities, [user])
31 |> :xmerl.export_simple(:xmerl_xml)
35 |> put_resp_content_type("application/atom+xml")
36 |> send_resp(200, response)
39 def salmon_incoming(conn, params) do
40 {:ok, body, _conn} = read_body(conn)
41 {:ok, magic_key} = Pleroma.Web.Salmon.fetch_magic_key(body)
42 {:ok, doc} = Pleroma.Web.Salmon.decode_and_validate(magic_key, body)
44 Federator.enqueue(:incoming_doc, doc)
50 def object(conn, %{"uuid" => uuid}) do
51 with id <- o_status_url(conn, :object, uuid),
52 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
53 %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
54 case get_format(conn) do
55 "html" -> redirect(conn, to: "/notice/#{activity.id}")
56 _ -> represent_activity(conn, activity, user)
61 def activity(conn, %{"uuid" => uuid}) do
62 with id <- o_status_url(conn, :activity, uuid),
63 %Activity{} = activity <- Activity.get_by_ap_id(id),
64 %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
65 case get_format(conn) do
66 "html" -> redirect(conn, to: "/notice/#{activity.id}")
67 _ -> represent_activity(conn, activity, user)
72 defp represent_activity(conn, activity, user) do
74 |> ActivityRepresenter.to_simple_form(user, true)
75 |> ActivityRepresenter.wrap_with_entry
76 |> :xmerl.export_simple(:xmerl_xml)
80 |> put_resp_content_type("application/atom+xml")
81 |> send_resp(200, response)