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