X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fviews%2Faccount_view.ex;h=190d6ebf235bf43d77af55c1ecd1f08195f86552;hb=a079ec3a3cdfd42d2cbd51c7698c2c87828e5778;hp=3158d09ed8dcd11cd10ab82292c74acd814b5ac6;hpb=77c239f3092af61d0896ae412e9180503dd98b00;p=akkoma
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 3158d09ed..190d6ebf2 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AccountView do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
alias Pleroma.FollowingRelationship
alias Pleroma.User
+ alias Pleroma.UserNote
alias Pleroma.UserRelationship
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
@@ -93,19 +94,28 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
followed_by =
if following_relationships do
- case FollowingRelationship.find(following_relationships, target, reading_user) do
- %{state: :follow_accept} -> true
- _ -> false
- end
+ target_to_user_following_relation =
+ FollowingRelationship.find(following_relationships, target, reading_user)
+
+ User.get_follow_state(target, reading_user, target_to_user_following_relation)
else
- User.following?(target, reading_user)
+ User.get_follow_state(target, reading_user)
end
+ subscribing =
+ UserRelationship.exists?(
+ user_relationships,
+ :inverse_subscription,
+ target,
+ reading_user,
+ &User.subscribed_to?(&2, &1)
+ )
+
# NOTE: adjust UserRelationship.view_relationships_option/2 on new relation-related flags
%{
id: to_string(target.id),
following: follow_state == :follow_accept,
- followed_by: followed_by,
+ followed_by: followed_by == :follow_accept,
blocking:
UserRelationship.exists?(
user_relationships,
@@ -138,15 +148,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
target,
&User.muted_notifications?(&1, &2)
),
- subscribing:
- UserRelationship.exists?(
- user_relationships,
- :inverse_subscription,
- target,
- reading_user,
- &User.subscribed_to?(&2, &1)
- ),
+ subscribing: subscribing,
+ notifying: subscribing,
requested: follow_state == :follow_pending,
+ requested_by: followed_by == :follow_pending,
domain_blocking: User.blocks_domain?(reading_user, target),
showing_reblogs:
not UserRelationship.exists?(
@@ -156,7 +161,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
target,
&User.muting_reblogs?(&1, &2)
),
- endorsed: false
+ endorsed: false,
+ note:
+ UserNote.show(
+ reading_user,
+ target
+ )
}
end
@@ -177,6 +187,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
render_many(targets, AccountView, "relationship.json", render_opts)
end
+ def render("instance.json", %{instance: %Pleroma.Instances.Instance{} = instance}) do
+ %{
+ name: instance.host,
+ favicon: instance.favicon |> MediaProxy.url(),
+ nodeinfo: instance.nodeinfo
+ }
+ end
+
+ def render("instance.json", _), do: nil
+
defp do_render("show.json", %{user: user} = opts) do
user = User.sanitize_html(user, User.html_filter_policy(opts[:for]))
display_name = user.name || user.nickname
@@ -187,18 +207,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true)
following_count =
- if !user.hide_follows_count or !user.hide_follows or opts[:for] == user do
- user.following_count || 0
- else
- 0
- end
+ if !user.hide_follows_count or !user.hide_follows or opts[:for] == user,
+ do: user.following_count,
+ else: 0
followers_count =
- if !user.hide_followers_count or !user.hide_followers or opts[:for] == user do
- user.follower_count || 0
- else
- 0
- end
+ if !user.hide_followers_count or !user.hide_followers or opts[:for] == user,
+ do: user.follower_count,
+ else: 0
bot = user.actor_type == "Service"
@@ -225,16 +241,20 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
%{}
end
- favicon =
- if Pleroma.Config.get([:instances_favicons, :enabled]) do
- user
- |> Map.get(:ap_id, "")
- |> URI.parse()
- |> URI.merge("/")
- |> Pleroma.Instances.Instance.get_or_update_favicon()
- |> MediaProxy.url()
+ instance =
+ with {:ok, instance} <- Pleroma.Instances.Instance.get_cached_by_url(user.ap_id) do
+ instance
else
+ _ ->
+ nil
+ end
+
+ favicon =
+ if is_nil(instance) do
nil
+ else
+ instance.favicon
+ |> MediaProxy.url()
end
%{
@@ -265,11 +285,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
actor_type: user.actor_type
}
},
-
- # Pleroma extension
+ last_status_at: user.last_status_at,
+ akkoma: %{
+ instance: render("instance.json", %{instance: instance}),
+ status_ttl_days: user.status_ttl_days
+ },
+ # Pleroma extensions
+ # Note: it's insecure to output :email but fully-qualified nickname may serve as safe stub
+ fqn: User.full_nickname(user),
pleroma: %{
ap_id: user.ap_id,
- confirmation_pending: user.confirmation_pending,
+ also_known_as: user.also_known_as,
+ is_confirmed: user.is_confirmed,
+ is_suggested: user.is_suggested,
tags: user.tags,
hide_followers_count: user.hide_followers_count,
hide_follows_count: user.hide_follows_count,
@@ -279,7 +307,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
relationship: relationship,
skip_thread_containment: user.skip_thread_containment,
background_image: image_url(user.background) |> MediaProxy.url(),
- accepts_chat_messages: user.accepts_chat_messages,
favicon: favicon
}
}
@@ -287,12 +314,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|> maybe_put_settings(user, opts[:for], opts)
|> maybe_put_notification_settings(user, opts[:for])
|> maybe_put_settings_store(user, opts[:for], opts)
- |> maybe_put_chat_token(user, opts[:for], opts)
|> maybe_put_activation_status(user, opts[:for])
|> maybe_put_follow_requests_count(user, opts[:for])
|> maybe_put_allow_following_move(user, opts[:for])
|> maybe_put_unread_conversation_count(user, opts[:for])
|> maybe_put_unread_notification_count(user, opts[:for])
+ |> maybe_put_email_address(user, opts[:for])
end
defp username_from_nickname(string) when is_binary(string) do
@@ -307,7 +334,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
%User{id: user_id}
) do
count =
- User.get_follow_requests(user)
+ user
+ |> User.get_follow_requests()
|> length()
data
@@ -339,15 +367,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_settings_store(data, _, _, _), do: data
- defp maybe_put_chat_token(data, %User{id: id}, %User{id: id}, %{
- with_chat_token: token
- }) do
- data
- |> Kernel.put_in([:pleroma, :chat_token], token)
- end
-
- defp maybe_put_chat_token(data, _, _, _), do: data
-
defp maybe_put_role(data, %User{show_role: true} = user, _) do
data
|> Kernel.put_in([:pleroma, :is_admin], user.is_admin)
@@ -379,7 +398,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_allow_following_move(data, _, _), do: data
defp maybe_put_activation_status(data, user, %User{is_admin: true}) do
- Kernel.put_in(data, [:pleroma, :deactivated], user.deactivated)
+ Kernel.put_in(data, [:pleroma, :deactivated], !user.is_active)
end
defp maybe_put_activation_status(data, _, _), do: data
@@ -404,6 +423,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_unread_notification_count(data, _, _), do: data
+ defp maybe_put_email_address(data, %User{id: user_id}, %User{id: user_id} = user) do
+ Kernel.put_in(
+ data,
+ [:pleroma, :email],
+ user.email
+ )
+ end
+
+ defp maybe_put_email_address(data, _, _), do: data
+
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
defp image_url(_), do: nil
end