ActivityPub: Refactor create function.
[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 last_activity = List.last(activities)
14
15 entries = activities
16 |> Enum.map(fn(activity) ->
17 {:entry, ActivityRepresenter.to_simple_form(activity, user)}
18 end)
19 |> Enum.filter(fn ({_, form}) -> form end)
20
21 [{
22 :feed, [
23 xmlns: 'http://www.w3.org/2005/Atom',
24 "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
25 "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
26 "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
27 "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
28 ], [
29 {:id, h.(OStatus.feed_path(user))},
30 {:title, ['#{user.nickname}\'s timeline']},
31 {:updated, h.(most_recent_update)},
32 {:logo, [to_charlist(User.avatar_url(user) |> MediaProxy.url())]},
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'], []},
36 {:author, UserRepresenter.to_simple_form(user)},
37 ] ++
38 if last_activity do
39 [{:link, [rel: 'next',
40 href: to_charlist(OStatus.feed_path(user)) ++ '?max_id=' ++ to_charlist(last_activity.id),
41 type: 'application/atom+xml'], []}]
42 else
43 []
44 end
45 ++ entries
46 }]
47 end
48 end