MastodonAPI.StatusView.get_user/1 --> CommonAPI.get_user/1
This commit is contained in:
parent
425324aae3
commit
f88dc1937e
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.AdminAPI.StatusView do
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.Web.AdminAPI
|
alias Pleroma.Web.AdminAPI
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI
|
alias Pleroma.Web.MastodonAPI
|
||||||
|
|
||||||
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
||||||
|
@ -17,7 +18,7 @@ def render("index.json", opts) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
||||||
user = MastodonAPI.StatusView.get_user(activity.data["actor"])
|
user = CommonAPI.get_user(activity.data["actor"])
|
||||||
|
|
||||||
MastodonAPI.StatusView.render("show.json", opts)
|
MastodonAPI.StatusView.render("show.json", opts)
|
||||||
|> Map.merge(%{account: merge_account_views(user)})
|
|> Map.merge(%{account: merge_account_views(user)})
|
||||||
|
|
|
@ -550,4 +550,21 @@ def hide_reblogs(%User{} = user, %User{} = target) do
|
||||||
def show_reblogs(%User{} = user, %User{} = target) do
|
def show_reblogs(%User{} = user, %User{} = target) do
|
||||||
UserRelationship.delete_reblog_mute(user, target)
|
UserRelationship.delete_reblog_mute(user, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_user(ap_id, fake_record_fallback \\ true) do
|
||||||
|
cond do
|
||||||
|
user = User.get_cached_by_ap_id(ap_id) ->
|
||||||
|
user
|
||||||
|
|
||||||
|
user = User.get_by_guessed_nickname(ap_id) ->
|
||||||
|
user
|
||||||
|
|
||||||
|
fake_record_fallback ->
|
||||||
|
# TODO: refactor (fake records is never a good idea)
|
||||||
|
User.error_user(ap_id)
|
||||||
|
|
||||||
|
true ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,23 +56,6 @@ defp get_replied_to_activities(activities) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_user(ap_id, fake_record_fallback \\ true) do
|
|
||||||
cond do
|
|
||||||
user = User.get_cached_by_ap_id(ap_id) ->
|
|
||||||
user
|
|
||||||
|
|
||||||
user = User.get_by_guessed_nickname(ap_id) ->
|
|
||||||
user
|
|
||||||
|
|
||||||
fake_record_fallback ->
|
|
||||||
# TODO: refactor (fake records is never a good idea)
|
|
||||||
User.error_user(ap_id)
|
|
||||||
|
|
||||||
true ->
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_context_id(%{data: %{"context_id" => context_id}}) when not is_nil(context_id),
|
defp get_context_id(%{data: %{"context_id" => context_id}}) when not is_nil(context_id),
|
||||||
do: context_id
|
do: context_id
|
||||||
|
|
||||||
|
@ -120,7 +103,7 @@ def render("index.json", opts) do
|
||||||
# Note: unresolved users are filtered out
|
# Note: unresolved users are filtered out
|
||||||
actors =
|
actors =
|
||||||
(activities ++ parent_activities)
|
(activities ++ parent_activities)
|
||||||
|> Enum.map(&get_user(&1.data["actor"], false))
|
|> Enum.map(&CommonAPI.get_user(&1.data["actor"], false))
|
||||||
|> Enum.filter(& &1)
|
|> Enum.filter(& &1)
|
||||||
|
|
||||||
UserRelationship.view_relationships_option(reading_user, actors, subset: :source_mutes)
|
UserRelationship.view_relationships_option(reading_user, actors, subset: :source_mutes)
|
||||||
|
@ -139,7 +122,7 @@ def render(
|
||||||
"show.json",
|
"show.json",
|
||||||
%{activity: %{data: %{"type" => "Announce", "object" => _object}} = activity} = opts
|
%{activity: %{data: %{"type" => "Announce", "object" => _object}} = activity} = opts
|
||||||
) do
|
) do
|
||||||
user = get_user(activity.data["actor"])
|
user = CommonAPI.get_user(activity.data["actor"])
|
||||||
created_at = Utils.to_masto_date(activity.data["published"])
|
created_at = Utils.to_masto_date(activity.data["published"])
|
||||||
activity_object = Object.normalize(activity)
|
activity_object = Object.normalize(activity)
|
||||||
|
|
||||||
|
@ -212,7 +195,7 @@ def render(
|
||||||
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
user = get_user(activity.data["actor"])
|
user = CommonAPI.get_user(activity.data["actor"])
|
||||||
user_follower_address = user.follower_address
|
user_follower_address = user.follower_address
|
||||||
|
|
||||||
like_count = object.data["like_count"] || 0
|
like_count = object.data["like_count"] || 0
|
||||||
|
@ -266,7 +249,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
|
||||||
|
|
||||||
reply_to = get_reply_to(activity, opts)
|
reply_to = get_reply_to(activity, opts)
|
||||||
|
|
||||||
reply_to_user = reply_to && get_user(reply_to.data["actor"])
|
reply_to_user = reply_to && CommonAPI.get_user(reply_to.data["actor"])
|
||||||
|
|
||||||
content =
|
content =
|
||||||
object
|
object
|
||||||
|
|
|
@ -10,14 +10,14 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
|
||||||
|
|
||||||
def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
|
def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
user = StatusView.get_user(activity.data["actor"])
|
user = CommonAPI.get_user(activity.data["actor"])
|
||||||
created_at = Utils.to_masto_date(activity.data["published"])
|
created_at = Utils.to_masto_date(activity.data["published"])
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -1126,4 +1126,24 @@ test "respects visibility=private" do
|
||||||
assert Visibility.get_visibility(activity) == "private"
|
assert Visibility.get_visibility(activity) == "private"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "get_user/1" do
|
||||||
|
test "gets user by ap_id" do
|
||||||
|
user = insert(:user)
|
||||||
|
assert CommonAPI.get_user(user.ap_id) == user
|
||||||
|
end
|
||||||
|
|
||||||
|
test "gets user by guessed nickname" do
|
||||||
|
user = insert(:user, ap_id: "", nickname: "mario@mushroom.kingdom")
|
||||||
|
assert CommonAPI.get_user("https://mushroom.kingdom/users/mario") == user
|
||||||
|
end
|
||||||
|
|
||||||
|
test "fallback" do
|
||||||
|
assert %User{
|
||||||
|
name: "",
|
||||||
|
ap_id: "",
|
||||||
|
nickname: "erroruser@example.com"
|
||||||
|
} = CommonAPI.get_user("")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue