From cb6fd738614a016fc143221a5ae588aa82f3a251 Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 12 Nov 2018 15:38:39 +0000 Subject: [PATCH 1/2] Twitter API: Fall back to user.nickname if user has no name --- lib/pleroma/web/twitter_api/views/user_view.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index a662f83b6..a100a1127 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -55,8 +55,12 @@ def render("user.json", %{user: user = %User{}} = assigns) do "statusnet_blocking" => statusnet_blocking, "friends_count" => user_info[:following_count], "id" => user.id, - "name" => user.name, - "name_html" => HTML.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, From db78c72868358eed6c07ee43a5f1427d545c45ed Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 12 Nov 2018 16:40:34 +0000 Subject: [PATCH 2/2] Twitter API: Add tests for nil names. --- test/web/twitter_api/views/user_view_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 2deb22fb1..2c583c0d3 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -13,6 +13,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do [user: user] end + test "A user with only a nickname", %{user: user} do + user = %{user | name: nil, nickname: "scarlett@catgirl.science"} + represented = UserView.render("show.json", %{user: user}) + assert represented["name"] == user.nickname + assert represented["name_html"] == user.nickname + end + test "A user with an avatar object", %{user: user} do image = "image" user = %{user | avatar: %{"url" => [%{"href" => image}]}}