10860ce04343b53ebb608012c1b061d658385029
[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 alias Pleroma.User
5 alias Pleroma.Web.MediaProxy
6
7 def to_simple_form(user, activities, _users) do
8 most_recent_update = (List.first(activities) || user).updated_at
9 |> NaiveDateTime.to_iso8601
10
11 h = fn(str) -> [to_charlist(str)] end
12
13 entries = activities
14 |> Enum.map(fn(activity) ->
15 {:entry, ActivityRepresenter.to_simple_form(activity, user)}
16 end)
17 |> Enum.filter(fn ({_, form}) -> form end)
18
19 [{
20 :feed, [
21 xmlns: 'http://www.w3.org/2005/Atom',
22 "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
23 "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
24 "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
25 "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
26 ], [
27 {:id, h.(OStatus.feed_path(user))},
28 {:title, ['#{user.nickname}\'s timeline']},
29 {:updated, h.(most_recent_update)},
30 {:logo, [to_charlist(User.avatar_url(user) |> MediaProxy.url())]},
31 {:link, [rel: 'hub', href: h.(OStatus.pubsub_path(user))], []},
32 {:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
33 {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'], []},
34 {:author, UserRepresenter.to_simple_form(user)},
35 ] ++ entries
36 }]
37 end
38 end