1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.FeedView do
9 alias Pleroma.Formatter
12 alias Pleroma.Web.MediaProxy
14 require Pleroma.Constants
16 @spec pub_date(String.t() | DateTime.t()) :: String.t()
17 def pub_date(date) when is_binary(date) do
19 |> Timex.parse!("{ISO:Extended}")
23 def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}")
25 def prepare_activity(activity) do
26 object = activity_object(activity)
30 data: Map.get(object, :data),
35 def most_recent_update(activities, user) do
36 (List.first(activities) || user).updated_at
37 |> NaiveDateTime.to_iso8601()
41 case Pleroma.Config.get([:feed, :logo]) do
43 "#{Pleroma.Web.base_url()}/static/logo.png"
46 "#{Pleroma.Web.base_url()}#{logo}"
57 def last_activity(activities), do: List.last(activities)
59 def activity_object(activity), do: Object.normalize(activity)
61 def activity_title(%{data: %{"content" => content}}, opts \\ %{}) do
63 |> Pleroma.Web.Metadata.Utils.scrub_html()
64 |> Pleroma.Emoji.Formatter.demojify()
65 |> Formatter.truncate(opts[:max_length], opts[:omission])
69 def activity_content(%{data: %{"content" => content}}) do
71 |> String.replace(~r/[\n\r]/, "")
75 def activity_content(_), do: ""
77 def activity_context(activity), do: activity.data["context"]
79 def attachment_href(attachment) do
85 def attachment_type(attachment) do
88 |> Map.get("mediaType")
92 with %Object{data: %{"external_url" => external_url}} <- Object.get_cached_by_ap_id(id) do