ostatus_controller.ex 1.69 KB
Newer Older
lain's avatar
lain committed
1
2
3
4
defmodule Pleroma.Web.OStatus.OStatusController do
  use Pleroma.Web, :controller

  alias Pleroma.{User, Activity}
5
  alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter}
lain's avatar
lain committed
6
  alias Pleroma.Repo
7
  alias Pleroma.Web.OStatus
lain's avatar
lain committed
8
9
  import Ecto.Query

10
11
12
13
14
  def feed_redirect(conn, %{"nickname" => nickname}) do
    user = User.get_cached_by_nickname(nickname)
    redirect conn, external: OStatus.feed_path(user)
  end

lain's avatar
lain committed
15
16
17
18
19
20
21
22
23
24
25
26
  def feed(conn, %{"nickname" => nickname}) do
    user = User.get_cached_by_nickname(nickname)
    query = from activity in Activity,
      where: fragment("? @> ?", activity.data, ^%{actor: user.ap_id}),
      limit: 20,
      order_by: [desc: :inserted_at]

    activities = query
    |> Repo.all

    response = FeedRepresenter.to_simple_form(user, activities, [user])
    |> :xmerl.export_simple(:xmerl_xml)
lain's avatar
lain committed
27
    |> to_string
lain's avatar
lain committed
28
29
30
31
32

    conn
    |> put_resp_content_type("application/atom+xml")
    |> send_resp(200, response)
  end
lain's avatar
lain committed
33

34
35
36
37
38
39
40
41
42
  def salmon_incoming(conn, params) do
    {:ok, body, _conn} = read_body(conn)
    magic_key = Pleroma.Web.Salmon.fetch_magic_key(body)
    {:ok, doc} = Pleroma.Web.Salmon.decode_and_validate(magic_key, body)

    Pleroma.Web.OStatus.handle_incoming(doc)

    conn
    |> send_resp(200, "")
lain's avatar
lain committed
43
  end
44
45
46
47
48
49

  def object(conn, %{"uuid" => uuid}) do
    id = o_status_url(conn, :object, uuid)
    activity = Activity.get_create_activity_by_object_ap_id(id)
    user = User.get_cached_by_ap_id(activity.data["actor"])

50
51
    response = ActivityRepresenter.to_simple_form(activity, user, true)
    |> ActivityRepresenter.wrap_with_entry
52
53
54
55
56
57
58
    |> :xmerl.export_simple(:xmerl_xml)
    |> to_string

    conn
    |> put_resp_content_type("application/atom+xml")
    |> send_resp(200, response)
  end
lain's avatar
lain committed
59
end