plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action == :lists)
+ plug(
+ OAuthScopesPlug,
+ %{scopes: ["follow", "read:blocks"]} when action == :blocks
+ )
+
plug(
OAuthScopesPlug,
%{scopes: ["follow", "write:blocks"]} when action in [:block, :unblock]
plug(OAuthScopesPlug, %{scopes: ["read:follows"]} when action == :relationships)
+ # Note: :follows (POST /api/v1/follows) is the same as :follow, consider removing :follows
plug(
OAuthScopesPlug,
- %{scopes: ["follow", "write:follows"]} when action in [:follow, :unfollow]
+ %{scopes: ["follow", "write:follows"]} when action in [:follows, :follow, :unfollow]
)
+ plug(OAuthScopesPlug, %{scopes: ["follow", "read:mutes"]} when action == :mutes)
+
plug(OAuthScopesPlug, %{scopes: ["follow", "write:mutes"]} when action in [:mute, :unmute])
plug(
|> Enum.concat(Emoji.Formatter.get_emoji_map(emojis_text))
|> Enum.dedup()
+ params =
+ if Map.has_key?(params, "fields_attributes") do
+ Map.update!(params, "fields_attributes", fn fields ->
+ fields
+ |> normalize_fields_attributes()
+ |> Enum.filter(fn %{"name" => n} -> n != "" end)
+ end)
+ else
+ params
+ end
+
info_params =
[
:no_rich_text,
add_if_present(acc, params, to_string(key), key, &{:ok, truthy_param?(&1)})
end)
|> add_if_present(params, "default_scope", :default_scope)
- |> add_if_present(params, "fields", :fields, fn fields ->
+ |> add_if_present(params, "fields_attributes", :fields, fn fields ->
fields = Enum.map(fields, fn f -> Map.update!(f, "value", &AutoLinker.link(&1)) end)
{:ok, fields}
end)
- |> add_if_present(params, "fields", :raw_fields)
+ |> add_if_present(params, "fields_attributes", :raw_fields)
|> add_if_present(params, "pleroma_settings_store", :pleroma_settings_store, fn value ->
{:ok, Map.merge(user.info.pleroma_settings_store, value)}
end)
end
end
+ defp normalize_fields_attributes(fields) do
+ if Enum.all?(fields, &is_tuple/1) do
+ Enum.map(fields, fn {_, v} -> v end)
+ else
+ fields
+ end
+ end
+
@doc "GET /api/v1/accounts/relationships"
def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
targets = User.get_all_by_ids(List.wrap(id))
end
end
+ @doc "POST /api/v1/follows"
+ def follows(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
+ with {_, %User{} = followed} <- {:followed, User.get_cached_by_nickname(uri)},
+ {_, true} <- {:followed, follower.id != followed.id},
+ {:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
+ render(conn, "show.json", user: followed, for: follower)
+ else
+ {:followed, _} -> {:error, :not_found}
+ {:error, message} -> json_response(conn, :forbidden, %{error: message})
+ end
+ end
+
+ @doc "GET /api/v1/mutes"
+ def mutes(%{assigns: %{user: user}} = conn, _) do
+ render(conn, "index.json", users: User.muted_users(user), for: user, as: :user)
+ end
+
+ @doc "GET /api/v1/blocks"
+ def blocks(%{assigns: %{user: user}} = conn, _) do
+ render(conn, "index.json", users: User.blocked_users(user), for: user, as: :user)
+ end
+
@doc "GET /api/v1/endorsements"
def endorsements(conn, params),
do: Pleroma.Web.MastodonAPI.MastodonAPIController.empty_array(conn, params)