Merge branch 'develop' into dtluna/pleroma-refactor/1
[akkoma] / lib / pleroma / web / ostatus / feed_representer.ex
1 defmodule Pleroma.Web.OStatus.FeedRepresenter do
2 alias Pleroma.Web.OStatus
3 alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter}
4
5 def to_simple_form(user, activities, users) do
6 most_recent_update = (List.first(activities) || user).updated_at
7 |> NaiveDateTime.to_iso8601
8
9 h = fn(str) -> [to_charlist(str)] end
10
11 entries = activities
12 |> Enum.map(fn(activity) ->
13 {:entry, ActivityRepresenter.to_simple_form(activity, user)}
14 end)
15 |> Enum.filter(fn ({_, form}) -> form end)
16
17 [{
18 :feed, [
19 xmlns: 'http://www.w3.org/2005/Atom',
20 "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
21 "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
22 "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
23 "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
24 ], [
25 {:id, h.(OStatus.feed_path(user))},
26 {:title, ['#{user.nickname}\'s timeline']},
27 {:updated, h.(most_recent_update)},
28 {:link, [rel: 'hub', href: h.(OStatus.pubsub_path(user))], []},
29 {:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
30 {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'], []},
31 {:author, UserRepresenter.to_simple_form(user)},
32 ] ++ entries
33 }]
34 end
35 end