X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Ffeed%2Ffeed_view.ex;h=1ae03e7e28d2d3651cb91a9134168e7f50beb2b9;hb=89e5b2046bd15b3fead7a6194a2b9cecd2fedbd3;hp=5eef1e7574478d1a8629874f41f2ee1e79d5acb4;hpb=35068baf65f1be9ac4e5ae8d08222244ae823fcc;p=akkoma
diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex
index 5eef1e757..1ae03e7e2 100644
--- a/lib/pleroma/web/feed/feed_view.ex
+++ b/lib/pleroma/web/feed/feed_view.ex
@@ -1,53 +1,89 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Feed.FeedView do
use Phoenix.HTML
use Pleroma.Web, :view
+ alias Pleroma.Formatter
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.MediaProxy
require Pleroma.Constants
+ @spec pub_date(String.t() | DateTime.t()) :: String.t()
+ def pub_date(date) when is_binary(date) do
+ date
+ |> Timex.parse!("{ISO:Extended}")
+ |> pub_date
+ end
+
+ def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}")
+
+ def prepare_activity(activity, opts \\ []) do
+ object = Object.normalize(activity)
+
+ actor =
+ if opts[:actor] do
+ Pleroma.User.get_cached_by_ap_id(activity.actor)
+ end
+
+ %{
+ activity: activity,
+ data: Map.get(object, :data),
+ actor: actor
+ }
+ end
+
+ def most_recent_update(activities) do
+ with %{updated_at: updated_at} <- List.first(activities) do
+ NaiveDateTime.to_iso8601(updated_at)
+ end
+ end
+
def most_recent_update(activities, user) do
(List.first(activities) || user).updated_at
|> NaiveDateTime.to_iso8601()
end
+ def feed_logo do
+ case Pleroma.Config.get([:feed, :logo]) do
+ nil ->
+ "#{Pleroma.Web.base_url()}/static/logo.png"
+
+ logo ->
+ "#{Pleroma.Web.base_url()}#{logo}"
+ end
+ |> MediaProxy.url()
+ end
+
def logo(user) do
user
|> User.avatar_url()
|> MediaProxy.url()
end
- def last_activity(activities) do
- List.last(activities)
- end
-
- def activity_object(activity) do
- Object.normalize(activity)
- end
+ def last_activity(activities), do: List.last(activities)
- def activity_object_data(activity) do
- activity
- |> activity_object()
- |> Map.get(:data)
+ def activity_title(%{"content" => content}, opts \\ %{}) do
+ content
+ |> Pleroma.Web.Metadata.Utils.scrub_html()
+ |> Pleroma.Emoji.Formatter.demojify()
+ |> Formatter.truncate(opts[:max_length], opts[:omission])
+ |> escape()
end
- def activity_content(activity) do
- content = activity_object_data(activity)["content"]
-
+ def activity_content(%{"content" => content}) do
content
|> String.replace(~r/[\n\r]/, "")
|> escape()
end
- def activity_context(activity) do
- activity.data["context"]
- end
+ def activity_content(_), do: ""
+
+ def activity_context(activity), do: activity.data["context"]
def attachment_href(attachment) do
attachment["url"]