X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fweb%2Ftwitter_api%2Fviews%2Fuser_view.ex;h=ede3c0d2590f1dd2f36ef052abf27de767284a60;hb=0a41786624454d26fd966748735a8f2333bf4012;hp=7d0f0e7039c9df5d0b77c35e463559615b440181;hpb=38361e7b5e24cbbd4654bd76fce4b3c66562ab59;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 7d0f0e703..ede3c0d25 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -1,27 +1,58 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 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.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
+ alias Pleroma.HTML
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("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}
@@ -30,18 +61,23 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
user_info = User.get_cached_user_info(user)
emoji =
- (user.info["source_data"]["tag"] || [])
+ (user.info.source_data["tag"] || [])
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
{String.trim(name, ":"), url}
end)
- bio = HtmlSanitizeEx.strip_tags(user.bio)
+ # ``fields`` is an array of mastodon profile field, containing ``{"name": "â¦", "value": "â¦"}``.
+ # For example: [{"name": "Pronoun", "value": "she/her"}, â¦]
+ fields =
+ (user.info.source_data["attachment"] || [])
+ |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
+ |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
data = %{
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
- "description" => bio,
- "description_html" => bio |> Formatter.emojify(emoji),
+ "description" => HTML.strip_tags((user.bio || "") |> String.replace("
", "\n")),
+ "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(for_user)),
"favourites_count" => 0,
"followers_count" => user_info[:follower_count],
"following" => following,
@@ -49,49 +85,47 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"statusnet_blocking" => statusnet_blocking,
"friends_count" => user_info[:following_count],
"id" => user.id,
- "name" => user.name,
- "name_html" => HtmlSanitizeEx.strip_tags(user.name) |> Formatter.emojify(emoji),
+ "name" => user.name || user.nickname,
+ "name_html" =>
+ if(user.name,
+ do: HTML.strip_tags(user.name) |> Formatter.emojify(emoji),
+ else: user.nickname
+ ),
"profile_image_url" => image,
"profile_image_url_https" => image,
"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
},
"screen_name" => user.nickname,
"statuses_count" => user_info[:note_count],
"statusnet_profile_url" => user.ap_id,
"cover_photo" => User.banner_url(user) |> MediaProxy.url(),
- "background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
+ "background_image" => image_url(user.info.background) |> MediaProxy.url(),
"is_local" => user.local,
- "locked" => !!user.info["locked"],
- "default_scope" => user.info["default_scope"] || "public"
+ "locked" => user.info.locked,
+ "default_scope" => user.info.default_scope,
+ "no_rich_text" => user.info.no_rich_text,
+ "fields" => fields,
+
+ # Pleroma extension
+ "pleroma" => %{
+ "confirmation_pending" => user_info.confirmation_pending,
+ "tags" => user.tags
+ }
}
if assigns[:token] do
- Map.put(data, "token", assigns[:token])
+ Map.put(data, "token", token_string(assigns[:token]))
else
data
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
- }
- end
-
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
defp image_url(_), do: nil
+
+ defp token_string(%Pleroma.Web.OAuth.Token{token: token_str}), do: token_str
+ defp token_string(token), do: token
end