Credo fixes: alias grouping/ordering
[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.User
7 alias Pleroma.Web.{OStatus, MediaProxy}
8 alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter}
9
10 def to_simple_form(user, activities, _users) do
11 most_recent_update =
12 (List.first(activities) || user).updated_at
13 |> NaiveDateTime.to_iso8601()
14
15 h = fn str -> [to_charlist(str)] end
16
17 last_activity = List.last(activities)
18
19 entries =
20 activities
21 |> Enum.map(fn activity ->
22 {:entry, ActivityRepresenter.to_simple_form(activity, user)}
23 end)
24 |> Enum.filter(fn {_, form} -> form end)
25
26 [
27 {
28 :feed,
29 [
30 xmlns: 'http://www.w3.org/2005/Atom',
31 "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
32 "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
33 "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
34 "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
35 ],
36 [
37 {:id, h.(OStatus.feed_path(user))},
38 {:title, ['#{user.nickname}\'s timeline']},
39 {:updated, h.(most_recent_update)},
40 {:logo, [to_charlist(User.avatar_url(user) |> MediaProxy.url())]},
41 {:link, [rel: 'hub', href: h.(OStatus.pubsub_path(user))], []},
42 {:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
43 {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'],
44 []},
45 {:author, UserRepresenter.to_simple_form(user)}
46 ] ++
47 if last_activity do
48 [
49 {:link,
50 [
51 rel: 'next',
52 href:
53 to_charlist(OStatus.feed_path(user)) ++
54 '?max_id=' ++ to_charlist(last_activity.id),
55 type: 'application/atom+xml'
56 ], []}
57 ]
58 else
59 []
60 end ++ entries
61 }
62 ]
63 end
64 end