X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fweb%2Ftwitter_api%2Fviews%2Fuser_view.ex;h=22f33e0b5d984bae61ad0269f1103705ec5b932d;hb=f38c316e6edbc88f1808a0c39488231ce17e4f35;hp=8a88d72b1bf07ed2d006bc1d7730b7566c66a4c0;hpb=ef318fb8a96ddf276393f4ec81d3242dd7c6a4d4;p=akkoma
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index 8a88d72b1..22f33e0b5 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -1,28 +1,72 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.UserView do
use Pleroma.Web, :view
- alias Pleroma.User
alias Pleroma.Formatter
+ alias Pleroma.HTML
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
- alias Pleroma.HTML
+ alias Pleroma.Web.TwitterAPI.UserView
def render("show.json", %{user: user = %User{}} = assigns) do
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
end
def render("index.json", %{users: users, for: user}) do
- render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
+ users
+ |> render_many(Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
+ |> Enum.filter(&Enum.any?/1)
end
def render("user.json", %{user: user = %User{}} = assigns) do
+ if User.visible_for?(user, assigns[:for]),
+ do: do_render("user.json", assigns),
+ else: %{}
+ end
+
+ def render("index_for_admin.json", %{users: users} = opts) do
+ users
+ |> render_many(UserView, "show_for_admin.json", opts)
+ end
+
+ def render("show_for_admin.json", %{user: user}) do
+ %{
+ "id" => user.id,
+ "nickname" => user.nickname,
+ "deactivated" => user.info.deactivated
+ }
+ end
+
+ def render("short.json", %{
+ user: %User{
+ nickname: nickname,
+ id: id,
+ ap_id: ap_id,
+ name: name
+ }
+ }) do
+ %{
+ "fullname" => name,
+ "id" => id,
+ "ostatus_uri" => ap_id,
+ "profile_url" => ap_id,
+ "screen_name" => nickname
+ }
+ end
+
+ defp do_render("user.json", %{user: user = %User{}} = assigns) do
+ for_user = assigns[:for]
image = User.avatar_url(user) |> MediaProxy.url()
{following, follows_you, statusnet_blocking} =
- if assigns[:for] do
+ if for_user do
{
- User.following?(assigns[:for], user),
- User.following?(user, assigns[:for]),
- User.blocks?(assigns[:for], user)
+ User.following?(for_user, user),
+ User.following?(user, for_user),
+ User.blocks?(for_user, user)
}
else
{false, false, false}
@@ -47,7 +91,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
data = %{
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"description" => HTML.strip_tags((user.bio || "") |> String.replace("
", "\n")),
- "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(assigns[:for])),
+ "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(for_user)),
"favourites_count" => 0,
"followers_count" => user_info[:follower_count],
"following" => following,
@@ -66,7 +110,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"profile_image_url_profile_size" => image,
"profile_image_url_original" => image,
"rights" => %{
- "delete_others_notice" => !!user.info.is_moderator
+ "delete_others_notice" => !!user.info.is_moderator,
+ "admin" => !!user.info.is_admin
},
"screen_name" => user.nickname,
"statuses_count" => user_info[:note_count],
@@ -77,14 +122,26 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"locked" => user.info.locked,
"default_scope" => user.info.default_scope,
"no_rich_text" => user.info.no_rich_text,
+ "hide_followers" => user.info.hide_followers,
+ "hide_follows" => user.info.hide_follows,
"fields" => fields,
# Pleroma extension
- "pleroma" => %{
- "tags" => user.tags
- }
+ "pleroma" =>
+ %{
+ "confirmation_pending" => user_info.confirmation_pending,
+ "tags" => user.tags
+ }
+ |> maybe_with_activation_status(user, for_user)
+ |> maybe_with_follow_request_count(user, for_user)
}
+ data =
+ if(user.info.is_admin || user.info.is_moderator,
+ do: maybe_with_role(data, user, for_user),
+ else: data
+ )
+
if assigns[:token] do
Map.put(data, "token", token_string(assigns[:token]))
else
@@ -92,23 +149,34 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
end
end
- def render("short.json", %{
- user: %User{
- nickname: nickname,
- id: id,
- ap_id: ap_id,
- name: name
- }
- }) do
- %{
- "fullname" => name,
- "id" => id,
- "ostatus_uri" => ap_id,
- "profile_url" => ap_id,
- "screen_name" => nickname
- }
+ defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
+ Map.put(data, "deactivated", user.info.deactivated)
+ end
+
+ defp maybe_with_activation_status(data, _, _), do: data
+
+ defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{
+ id: id
+ }) do
+ Map.put(data, "follow_request_count", user.info.follow_request_count)
end
+ defp maybe_with_follow_request_count(data, _, _), do: data
+
+ defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
+ Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role})
+ end
+
+ defp maybe_with_role(data, %User{info: %{show_role: true}} = user, _user) do
+ Map.merge(data, %{"role" => role(user)})
+ end
+
+ defp maybe_with_role(data, _, _), do: data
+
+ defp role(%User{info: %{:is_admin => true}}), do: "admin"
+ defp role(%User{info: %{:is_moderator => true}}), do: "moderator"
+ defp role(_), do: "member"
+
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
defp image_url(_), do: nil