feed_representer.ex 1.42 KB
Newer Older
lain's avatar
lain committed
1
2
defmodule Pleroma.Web.OStatus.FeedRepresenter do
  alias Pleroma.Web.OStatus
lain's avatar
lain committed
3
  alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter}
Hakaba Hitoyo's avatar
Hakaba Hitoyo committed
4
5
  alias Pleroma.User
  alias Pleroma.Web.MediaProxy
lain's avatar
lain committed
6

Thog's avatar
Thog committed
7
  def to_simple_form(user, activities, _users) do
lain's avatar
lain committed
8
    most_recent_update = (List.first(activities) || user).updated_at
lain's avatar
lain committed
9
10
11
12
    |> NaiveDateTime.to_iso8601

    h = fn(str) -> [to_charlist(str)] end

13
14
    entries = activities
    |> Enum.map(fn(activity) ->
lain's avatar
lain committed
15
16
      {:entry, ActivityRepresenter.to_simple_form(activity, user)}
    end)
lain's avatar
lain committed
17
    |> Enum.filter(fn ({_, form}) -> form end)
lain's avatar
lain committed
18

lain's avatar
lain committed
19
20
21
    [{
      :feed, [
        xmlns: 'http://www.w3.org/2005/Atom',
22
        "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
lain's avatar
lain committed
23
        "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
lain's avatar
lain committed
24
25
        "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
        "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
lain's avatar
lain committed
26
27
28
29
      ], [
        {:id, h.(OStatus.feed_path(user))},
        {:title, ['#{user.nickname}\'s timeline']},
        {:updated, h.(most_recent_update)},
30
        {:logo, [to_charlist(User.avatar_url(user) |> MediaProxy.url())]},
lain's avatar
lain committed
31
        {:link, [rel: 'hub', href: h.(OStatus.pubsub_path(user))], []},
32
        {:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
lain's avatar
lain committed
33
        {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'], []},
lain's avatar
lain committed
34
        {:author, UserRepresenter.to_simple_form(user)},
lain's avatar
lain committed
35
      ] ++ entries
lain's avatar
lain committed
36
37
38
    }]
  end
end