update copyright years to 2019
[akkoma] / lib / pleroma / web / ostatus / feed_representer.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OStatus.FeedRepresenter do
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter}
8 alias Pleroma.User
9 alias Pleroma.Web.MediaProxy
10
11 def to_simple_form(user, activities, _users) do
12 most_recent_update =
13 (List.first(activities) || user).updated_at
14 |> NaiveDateTime.to_iso8601()
15
16 h = fn str -> [to_charlist(str)] end
17
18 last_activity = List.last(activities)
19
20 entries =
21 activities
22 |> Enum.map(fn activity ->
23 {:entry, ActivityRepresenter.to_simple_form(activity, user)}
24 end)
25 |> Enum.filter(fn {_, form} -> form end)
26
27 [
28 {
29 :feed,
30 [
31 xmlns: 'http://www.w3.org/2005/Atom',
32 "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
33 "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
34 "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
35 "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
36 ],
37 [
38 {:id, h.(OStatus.feed_path(user))},
39 {:title, ['#{user.nickname}\'s timeline']},
40 {:updated, h.(most_recent_update)},
41 {:logo, [to_charlist(User.avatar_url(user) |> MediaProxy.url())]},
42 {:link, [rel: 'hub', href: h.(OStatus.pubsub_path(user))], []},
43 {:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
44 {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'],
45 []},
46 {:author, UserRepresenter.to_simple_form(user)}
47 ] ++
48 if last_activity do
49 [
50 {:link,
51 [
52 rel: 'next',
53 href:
54 to_charlist(OStatus.feed_path(user)) ++
55 '?max_id=' ++ to_charlist(last_activity.id),
56 type: 'application/atom+xml'
57 ], []}
58 ]
59 else
60 []
61 end ++ entries
62 }
63 ]
64 end
65 end