X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Ffeed%2Fuser_controller.ex;h=dc3b1f94b526fe13ab59f8f3f3420897c2d87482;hb=68894089e845220e06d77401d15e399cb0d3882c;hp=cf04fd49725ab65c9aa5ccf18ed1d99b0be85449;hpb=41e233200730dca4a0d6d846d44653eef4de0fec;p=akkoma
diff --git a/lib/pleroma/web/feed/user_controller.ex b/lib/pleroma/web/feed/user_controller.ex
index cf04fd497..dc3b1f94b 100644
--- a/lib/pleroma/web/feed/user_controller.ex
+++ b/lib/pleroma/web/feed/user_controller.ex
@@ -1,25 +1,25 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Feed.UserController do
use Pleroma.Web, :controller
- alias Fallback.RedirectController
+ alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.ActivityPubController
alias Pleroma.Web.Feed.FeedView
- import Pleroma.Web.ControllerHelper, only: [put_in_if_exist: 3]
-
- plug(Pleroma.Plugs.SetFormatPlug when action in [:feed_redirect])
+ plug(Pleroma.Web.Plugs.SetFormatPlug when action in [:feed_redirect])
action_fallback(:errors)
def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname}) do
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname_or_id(nickname)} do
- RedirectController.redirector_with_meta(conn, %{user: user})
+ Pleroma.Web.Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
+ else
+ _ -> Pleroma.Web.Fallback.RedirectController.redirector(conn, nil)
end
end
@@ -30,24 +30,38 @@ defmodule Pleroma.Web.Feed.UserController do
def feed_redirect(conn, %{"nickname" => nickname}) do
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
- redirect(conn, external: "#{user_feed_url(conn, :feed, user.nickname)}.atom")
+ redirect(conn, external: "#{Routes.user_feed_url(conn, :feed, user.nickname)}.atom")
end
end
def feed(conn, %{"nickname" => nickname} = params) do
- with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
+ format = get_format(conn)
+
+ format =
+ if format in ["atom", "rss"] do
+ format
+ else
+ "atom"
+ end
+
+ with {_, %User{local: true} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)},
+ {_, :visible} <- {:visibility, User.visible_for(user, _reading_user = nil)} do
activities =
- %{"type" => ["Create"], "whole_db" => true, "actor_id" => user.ap_id}
- |> put_in_if_exist("max_id", params["max_id"])
- |> ActivityPub.fetch_public_activities()
+ %{
+ type: ["Create"],
+ actor_id: user.ap_id
+ }
+ |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
+ |> ActivityPub.fetch_public_or_unlisted_activities()
conn
- |> put_resp_content_type("application/atom+xml")
+ |> put_resp_content_type("application/#{format}+xml")
|> put_view(FeedView)
- |> render("user.xml",
+ |> render("user.#{format}",
user: user,
activities: activities,
- feed_config: Pleroma.Config.get([:feed])
+ feed_config: Config.get([:feed]),
+ view_module: FeedView
)
end
end
@@ -56,8 +70,11 @@ defmodule Pleroma.Web.Feed.UserController do
render_error(conn, :not_found, "Not found")
end
+ def errors(conn, {:fetch_user, %User{local: false}}), do: errors(conn, {:error, :not_found})
def errors(conn, {:fetch_user, nil}), do: errors(conn, {:error, :not_found})
+ def errors(conn, {:visibility, _}), do: errors(conn, {:error, :not_found})
+
def errors(conn, _) do
render_error(conn, :internal_server_error, "Something went wrong")
end