1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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, opts \\ []) do
26 object = Object.normalize(activity)
30 Pleroma.User.get_cached_by_ap_id(activity.actor)
35 data: Map.get(object, :data),
40 def most_recent_update(activities) do
41 with %{updated_at: updated_at} <- List.first(activities) do
42 NaiveDateTime.to_iso8601(updated_at)
46 def most_recent_update(activities, user) do
47 (List.first(activities) || user).updated_at
48 |> NaiveDateTime.to_iso8601()
52 case Pleroma.Config.get([:feed, :logo]) do
54 "#{Pleroma.Web.base_url()}/static/logo.png"
57 "#{Pleroma.Web.base_url()}#{logo}"
68 def last_activity(activities), do: List.last(activities)
70 def activity_title(%{"content" => content}, opts \\ %{}) do
72 |> Pleroma.Web.Metadata.Utils.scrub_html()
73 |> Pleroma.Emoji.Formatter.demojify()
74 |> Formatter.truncate(opts[:max_length], opts[:omission])
78 def activity_content(%{"content" => content}) do
80 |> String.replace(~r/[\n\r]/, "")
84 def activity_content(_), do: ""
86 def activity_context(activity), do: activity.data["context"]
88 def attachment_href(attachment) do
94 def attachment_type(attachment) do
97 |> Map.get("mediaType")
101 with %Object{data: %{"external_url" => external_url}} <- Object.get_cached_by_ap_id(id) do