Several twitter api fixes.
This commit is contained in:
parent
40d9d2098c
commit
fbb70d25fe
4 changed files with 14 additions and 21 deletions
|
@ -4,6 +4,7 @@ defmodule Pleroma.User.Info do
|
||||||
|
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:banner, :map, default: %{})
|
field(:banner, :map, default: %{})
|
||||||
|
field(:background, :string, default: nil)
|
||||||
field(:source_data, :map, default: %{})
|
field(:source_data, :map, default: %{})
|
||||||
field(:note_count, :integer, default: 0)
|
field(:note_count, :integer, default: 0)
|
||||||
field(:follower_count, :integer, default: 0)
|
field(:follower_count, :integer, default: 0)
|
||||||
|
|
|
@ -148,7 +148,7 @@ def register_user(params) do
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
registrations_open || (!is_nil(token) && !token.used) ->
|
registrations_open || (!is_nil(token) && !token.used) ->
|
||||||
changeset = User.register_changeset(%User{}, params)
|
changeset = User.register_changeset(%User{info: %{}}, params)
|
||||||
|
|
||||||
with {:ok, user} <- Repo.insert(changeset) do
|
with {:ok, user} <- Repo.insert(changeset) do
|
||||||
!registrations_open && UserInviteToken.mark_as_used(token.token)
|
!registrations_open && UserInviteToken.mark_as_used(token.token)
|
||||||
|
@ -279,14 +279,6 @@ def conversation_id_to_context(id) do
|
||||||
|
|
||||||
def get_external_profile(for_user, uri) do
|
def get_external_profile(for_user, uri) do
|
||||||
with %User{} = user <- User.get_or_fetch(uri) do
|
with %User{} = user <- User.get_or_fetch(uri) do
|
||||||
spawn(fn ->
|
|
||||||
with url <- user.info["topic"],
|
|
||||||
{:ok, %{body: body}} <-
|
|
||||||
@httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do
|
|
||||||
OStatus.handle_incoming(body)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
{:ok, UserView.render("show.json", %{user: user, for: for_user})}
|
{:ok, UserView.render("show.json", %{user: user, for: for_user})}
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
|
|
|
@ -31,7 +31,7 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
user_info = User.get_cached_user_info(user)
|
user_info = User.get_cached_user_info(user)
|
||||||
|
|
||||||
emoji =
|
emoji =
|
||||||
(user.info["source_data"]["tag"] || [])
|
(user.info.source_data["tag"] || [])
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
||||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
||||||
{String.trim(name, ":"), url}
|
{String.trim(name, ":"), url}
|
||||||
|
@ -40,7 +40,7 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
|
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
|
||||||
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
|
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
|
||||||
fields =
|
fields =
|
||||||
(user.info["source_data"]["attachment"] || [])
|
(user.info.source_data["attachment"] || [])
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
||||||
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
||||||
|
|
||||||
|
@ -66,17 +66,17 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
"profile_image_url_profile_size" => image,
|
"profile_image_url_profile_size" => image,
|
||||||
"profile_image_url_original" => image,
|
"profile_image_url_original" => image,
|
||||||
"rights" => %{
|
"rights" => %{
|
||||||
"delete_others_notice" => !!user.info["is_moderator"]
|
"delete_others_notice" => !!user.info.is_moderator
|
||||||
},
|
},
|
||||||
"screen_name" => user.nickname,
|
"screen_name" => user.nickname,
|
||||||
"statuses_count" => user_info[:note_count],
|
"statuses_count" => user_info[:note_count],
|
||||||
"statusnet_profile_url" => user.ap_id,
|
"statusnet_profile_url" => user.ap_id,
|
||||||
"cover_photo" => User.banner_url(user) |> MediaProxy.url(),
|
"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,
|
"is_local" => user.local,
|
||||||
"locked" => !!user.info["locked"],
|
"locked" => user.info.locked,
|
||||||
"default_scope" => user.info["default_scope"] || "public",
|
"default_scope" => user.info.default_scope,
|
||||||
"no_rich_text" => user.info["no_rich_text"] || false,
|
"no_rich_text" => user.info.no_rich_text,
|
||||||
"fields" => fields
|
"fields" => fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||||
|
|
||||||
test "create a status" do
|
test "create a status" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
_mentioned_user = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
_mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
|
||||||
|
|
||||||
object_data = %{
|
object_data = %{
|
||||||
"type" => "Image",
|
"type" => "Image",
|
||||||
|
@ -67,7 +67,7 @@ test "create a status" do
|
||||||
|
|
||||||
user = User.get_by_ap_id(user.ap_id)
|
user = User.get_by_ap_id(user.ap_id)
|
||||||
|
|
||||||
assert user.info["note_count"] == 1
|
assert user.info.note_count == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create a status that is a reply" do
|
test "create a status that is a reply" do
|
||||||
|
@ -116,7 +116,7 @@ test "Follow another user using screen_name" do
|
||||||
assert User.ap_followers(followed) in user.following
|
assert User.ap_followers(followed) in user.following
|
||||||
|
|
||||||
followed = User.get_by_ap_id(followed.ap_id)
|
followed = User.get_by_ap_id(followed.ap_id)
|
||||||
assert followed.info["follower_count"] == 1
|
assert followed.info.follower_count == 1
|
||||||
|
|
||||||
{:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
{:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||||
|
@ -169,7 +169,7 @@ test "Unblock another user using user_id" do
|
||||||
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})
|
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})
|
||||||
|
|
||||||
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
|
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
|
||||||
assert user.info["blocks"] == []
|
assert user.info.blocks == []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Unblock another user using screen_name" do
|
test "Unblock another user using screen_name" do
|
||||||
|
@ -178,7 +178,7 @@ test "Unblock another user using screen_name" do
|
||||||
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})
|
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})
|
||||||
|
|
||||||
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
|
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
|
||||||
assert user.info["blocks"] == []
|
assert user.info.blocks == []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "upload a file" do
|
test "upload a file" do
|
||||||
|
|
Loading…
Reference in a new issue