2019-10-07 12:20:41 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-10-07 12:20:41 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-12-06 06:32:29 +00:00
|
|
|
defmodule Pleroma.Web.Feed.UserController do
|
2019-10-07 12:20:41 +00:00
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
2020-10-17 10:33:57 +00:00
|
|
|
alias Pleroma.Config
|
2019-10-07 12:20:41 +00:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPubController
|
2019-12-06 06:32:29 +00:00
|
|
|
alias Pleroma.Web.Feed.FeedView
|
2019-10-07 12:20:41 +00:00
|
|
|
|
2020-06-24 06:26:17 +00:00
|
|
|
plug(Pleroma.Web.Plugs.SetFormatPlug when action in [:feed_redirect])
|
2019-10-07 12:20:41 +00:00
|
|
|
|
|
|
|
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
|
2020-06-23 18:10:32 +00:00
|
|
|
Pleroma.Web.Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
|
2021-08-17 23:32:32 +00:00
|
|
|
else
|
|
|
|
_ -> Pleroma.Web.Fallback.RedirectController.redirector(conn, nil)
|
2019-10-07 12:20:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def feed_redirect(%{assigns: %{format: format}} = conn, _params)
|
|
|
|
when format in ["json", "activity+json"] do
|
2020-10-01 18:41:22 +00:00
|
|
|
ActivityPubController.call(conn, :user)
|
2019-10-07 12:20:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def feed_redirect(conn, %{"nickname" => nickname}) do
|
|
|
|
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
|
2021-05-18 22:11:25 +00:00
|
|
|
redirect(conn, external: "#{Routes.user_feed_url(conn, :feed, user.nickname)}.atom")
|
2019-10-07 12:20:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-05 20:48:00 +00:00
|
|
|
def feed(conn, %{"nickname" => nickname} = params) do
|
2020-03-13 14:41:26 +00:00
|
|
|
format = get_format(conn)
|
|
|
|
|
|
|
|
format =
|
2020-10-02 19:18:02 +00:00
|
|
|
if format in ["atom", "rss"] do
|
2020-03-13 14:41:26 +00:00
|
|
|
format
|
|
|
|
else
|
|
|
|
"atom"
|
|
|
|
end
|
|
|
|
|
2020-10-05 20:48:00 +00:00
|
|
|
with {_, %User{local: true} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)},
|
|
|
|
{_, :visible} <- {:visibility, User.visible_for(user, _reading_user = nil)} do
|
2019-10-07 12:20:41 +00:00
|
|
|
activities =
|
2019-11-08 06:23:24 +00:00
|
|
|
%{
|
2020-06-04 17:33:16 +00:00
|
|
|
type: ["Create"],
|
|
|
|
actor_id: user.ap_id
|
2019-11-08 06:23:24 +00:00
|
|
|
}
|
2020-06-05 19:15:10 +00:00
|
|
|
|> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
|
2020-05-25 20:27:47 +00:00
|
|
|
|> ActivityPub.fetch_public_or_unlisted_activities()
|
2019-10-07 12:20:41 +00:00
|
|
|
|
|
|
|
conn
|
2020-03-13 14:41:26 +00:00
|
|
|
|> put_resp_content_type("application/#{format}+xml")
|
2019-12-06 06:32:29 +00:00
|
|
|
|> put_view(FeedView)
|
2020-03-13 14:41:26 +00:00
|
|
|
|> render("user.#{format}",
|
2019-11-08 06:23:24 +00:00
|
|
|
user: user,
|
|
|
|
activities: activities,
|
2022-07-18 00:56:35 +00:00
|
|
|
feed_config: Config.get([:feed]),
|
|
|
|
view_module: FeedView
|
2019-11-08 06:23:24 +00:00
|
|
|
)
|
2019-10-07 12:20:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors(conn, {:error, :not_found}) do
|
|
|
|
render_error(conn, :not_found, "Not found")
|
|
|
|
end
|
|
|
|
|
2020-07-29 12:02:02 +00:00
|
|
|
def errors(conn, {:fetch_user, %User{local: false}}), do: errors(conn, {:error, :not_found})
|
2019-10-07 12:20:41 +00:00
|
|
|
def errors(conn, {:fetch_user, nil}), do: errors(conn, {:error, :not_found})
|
|
|
|
|
2020-10-05 20:48:00 +00:00
|
|
|
def errors(conn, {:visibility, _}), do: errors(conn, {:error, :not_found})
|
|
|
|
|
2019-10-07 12:20:41 +00:00
|
|
|
def errors(conn, _) do
|
|
|
|
render_error(conn, :internal_server_error, "Something went wrong")
|
|
|
|
end
|
|
|
|
end
|