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

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

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

13 14
    last_activity = List.last(activities)

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

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