More Jason changes.
This commit is contained in:
parent
527e803758
commit
d2099c849d
|
@ -58,7 +58,7 @@ defp halt_or_continue(conn, %{optional: true}) do
|
||||||
defp halt_or_continue(conn, _) do
|
defp halt_or_continue(conn, _) do
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{error: "Invalid credentials."}))
|
|> send_resp(403, Jason.encode!(%{error: "Invalid credentials."}))
|
||||||
|> halt
|
|> halt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -305,7 +305,7 @@ def user_data_from_user_object(data) do
|
||||||
|
|
||||||
def fetch_and_prepare_user_from_ap_id(ap_id) do
|
def fetch_and_prepare_user_from_ap_id(ap_id) do
|
||||||
with {:ok, %{status_code: 200, body: body}} <- @httpoison.get(ap_id, ["Accept": "application/activity+json"]),
|
with {:ok, %{status_code: 200, body: body}} <- @httpoison.get(ap_id, ["Accept": "application/activity+json"]),
|
||||||
{:ok, data} <- Poison.decode(body) do
|
{:ok, data} <- Jason.decode(body) do
|
||||||
user_data_from_user_object(data)
|
user_data_from_user_object(data)
|
||||||
else
|
else
|
||||||
e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
|
e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
|
||||||
|
@ -348,7 +348,7 @@ def publish(actor, activity) do
|
||||||
|> Enum.uniq
|
|> Enum.uniq
|
||||||
|
|
||||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
json = Poison.encode!(data)
|
json = Jason.encode!(data)
|
||||||
Enum.each remote_inboxes, fn(inbox) ->
|
Enum.each remote_inboxes, fn(inbox) ->
|
||||||
Federator.enqueue(:publish_single_ap, %{inbox: inbox, json: json, actor: actor, id: activity.data["id"]})
|
Federator.enqueue(:publish_single_ap, %{inbox: inbox, json: json, actor: actor, id: activity.data["id"]})
|
||||||
end
|
end
|
||||||
|
@ -370,7 +370,7 @@ def fetch_object_from_id(id) do
|
||||||
Logger.info("Fetching #{id} via AP")
|
Logger.info("Fetching #{id} via AP")
|
||||||
with true <- String.starts_with?(id, "http"),
|
with true <- String.starts_with?(id, "http"),
|
||||||
{:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(id, [Accept: "application/activity+json"], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
|
{:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(id, [Accept: "application/activity+json"], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
|
||||||
{:ok, data} <- Poison.decode(body),
|
{:ok, data} <- Jason.decode(body),
|
||||||
nil <- Object.get_by_ap_id(data["id"]),
|
nil <- Object.get_by_ap_id(data["id"]),
|
||||||
params <- %{"type" => "Create", "to" => data["to"], "cc" => data["cc"], "actor" => data["attributedTo"], "object" => data},
|
params <- %{"type" => "Create", "to" => data["to"], "cc" => data["cc"], "actor" => data["attributedTo"], "object" => data},
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
|
|
|
@ -284,7 +284,7 @@ def get_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params)
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{"error" => reason}))
|
|> send_resp(403, Jason.encode!(%{"error" => reason}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ def dismiss_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _para
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{"error" => reason}))
|
|> send_resp(403, Jason.encode!(%{"error" => reason}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{"error" => message}))
|
|> send_resp(403, Jason.encode!(%{"error" => message}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{"error" => message}))
|
|> send_resp(403, Jason.encode!(%{"error" => message}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{"error" => message}))
|
|> send_resp(403, Jason.encode!(%{"error" => message}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/json")
|
|> put_resp_content_type("application/json")
|
||||||
|> send_resp(403, Poison.encode!(%{"error" => message}))
|
|> send_resp(403, Jason.encode!(%{"error" => message}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do
|
||||||
push_subscription: nil,
|
push_subscription: nil,
|
||||||
accounts: accounts,
|
accounts: accounts,
|
||||||
custom_emojis: mastodon_emoji
|
custom_emojis: mastodon_emoji
|
||||||
} |> Poison.encode!
|
} |> Jason.encode!
|
||||||
conn
|
conn
|
||||||
|> put_layout(false)
|
|> put_layout(false)
|
||||||
|> render(MastodonView, "index.html", %{initial_state: initial_state})
|
|> render(MastodonView, "index.html", %{initial_state: initial_state})
|
||||||
|
|
|
@ -42,8 +42,8 @@ def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item},
|
||||||
Enum.each(topics[topic] || [], fn (socket) ->
|
Enum.each(topics[topic] || [], fn (socket) ->
|
||||||
json = %{
|
json = %{
|
||||||
event: "notification",
|
event: "notification",
|
||||||
payload: Pleroma.Web.MastodonAPI.MastodonAPIController.render_notification(socket.assigns["user"], item) |> Poison.encode!
|
payload: Pleroma.Web.MastodonAPI.MastodonAPIController.render_notification(socket.assigns["user"], item) |> Jason.encode!
|
||||||
} |> Poison.encode!
|
} |> Jason.encode!
|
||||||
|
|
||||||
send socket.transport_pid, {:text, json}
|
send socket.transport_pid, {:text, json}
|
||||||
end)
|
end)
|
||||||
|
@ -95,8 +95,8 @@ def push_to_socket(topics, topic, item) do
|
||||||
Enum.each(topics[topic] || [], fn (socket) ->
|
Enum.each(topics[topic] || [], fn (socket) ->
|
||||||
json = %{
|
json = %{
|
||||||
event: "update",
|
event: "update",
|
||||||
payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Poison.encode!
|
payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Jason.encode!
|
||||||
} |> Poison.encode!
|
} |> Jason.encode!
|
||||||
|
|
||||||
send socket.transport_pid, {:text, json}
|
send socket.transport_pid, {:text, json}
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -5,7 +5,7 @@ def to_json(object) do to_json(object, %{}) end
|
||||||
def to_json(object, options) do
|
def to_json(object, options) do
|
||||||
object
|
object
|
||||||
|> to_map(options)
|
|> to_map(options)
|
||||||
|> Poison.encode!
|
|> Jason.encode!
|
||||||
end
|
end
|
||||||
|
|
||||||
def enum_to_list(enum, options) do
|
def enum_to_list(enum, options) do
|
||||||
|
@ -21,7 +21,7 @@ def enum_to_json(enum) do enum_to_json(enum, %{}) end
|
||||||
def enum_to_json(enum, options) do
|
def enum_to_json(enum, options) do
|
||||||
enum
|
enum
|
||||||
|> enum_to_list(options)
|
|> enum_to_list(options)
|
||||||
|> Poison.encode!
|
|> Jason.encode!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -169,7 +169,7 @@ def upload(%Plug.Upload{} = file, format \\ "xml") do
|
||||||
media_id_string: "#{object.id}}",
|
media_id_string: "#{object.id}}",
|
||||||
media_url: href,
|
media_url: href,
|
||||||
size: 0
|
size: 0
|
||||||
} |> Poison.encode!
|
} |> Jason.encode!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ def register_user(params) do
|
||||||
else
|
else
|
||||||
{:error, changeset} ->
|
{:error, changeset} ->
|
||||||
errors = Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
|
errors = Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
|
||||||
|> Poison.encode!
|
|> Jason.encode!
|
||||||
{:error, %{error: errors}}
|
{:error, %{error: errors}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ defp extract_media_ids(status_data) do
|
||||||
|
|
||||||
def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
|
def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
statuses = TwitterAPI.fetch_public_and_external_statuses(user, params)
|
statuses = TwitterAPI.fetch_public_and_external_statuses(user, params)
|
||||||
{:ok, json} = Poison.encode(statuses)
|
{:ok, json} = Jason.encode(statuses)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, json)
|
|> json_reply(200, json)
|
||||||
|
@ -52,7 +52,7 @@ def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
|
||||||
def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
statuses = TwitterAPI.fetch_public_statuses(user, params)
|
statuses = TwitterAPI.fetch_public_statuses(user, params)
|
||||||
{:ok, json} = Poison.encode(statuses)
|
{:ok, json} = Jason.encode(statuses)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, json)
|
|> json_reply(200, json)
|
||||||
|
@ -60,7 +60,7 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
|
||||||
def friends_timeline(%{assigns: %{user: user}} = conn, params) do
|
def friends_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
statuses = TwitterAPI.fetch_friend_statuses(user, params)
|
statuses = TwitterAPI.fetch_friend_statuses(user, params)
|
||||||
{:ok, json} = Poison.encode(statuses)
|
{:ok, json} = Jason.encode(statuses)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, json)
|
|> json_reply(200, json)
|
||||||
|
@ -85,7 +85,7 @@ def user_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
params = Map.merge(params, %{"actor_id" => target_user.ap_id, "whole_db" => true})
|
params = Map.merge(params, %{"actor_id" => target_user.ap_id, "whole_db" => true})
|
||||||
statuses = TwitterAPI.fetch_user_statuses(user, params)
|
statuses = TwitterAPI.fetch_user_statuses(user, params)
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, statuses |> Poison.encode!)
|
|> json_reply(200, statuses |> Jason.encode!)
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
bad_request_reply(conn, msg)
|
bad_request_reply(conn, msg)
|
||||||
end
|
end
|
||||||
|
@ -93,7 +93,7 @@ def user_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
|
||||||
def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
|
def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
statuses = TwitterAPI.fetch_mentions(user, params)
|
statuses = TwitterAPI.fetch_mentions(user, params)
|
||||||
{:ok, json} = Poison.encode(statuses)
|
{:ok, json} = Jason.encode(statuses)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, json)
|
|> json_reply(200, json)
|
||||||
|
@ -140,7 +140,7 @@ def unfollow(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
response = Poison.encode!(TwitterAPI.fetch_status(user, id))
|
response = Jason.encode!(TwitterAPI.fetch_status(user, id))
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
|
@ -148,7 +148,7 @@ def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
|
|
||||||
def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
id = String.to_integer(id)
|
id = String.to_integer(id)
|
||||||
response = Poison.encode!(TwitterAPI.fetch_conversation(user, id))
|
response = Jason.encode!(TwitterAPI.fetch_conversation(user, id))
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
|
@ -200,7 +200,7 @@ def register(conn, params) do
|
||||||
else
|
else
|
||||||
{:error, errors} ->
|
{:error, errors} ->
|
||||||
conn
|
conn
|
||||||
|> json_reply(400, Poison.encode!(errors))
|
|> json_reply(400, Jason.encode!(errors))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ def update_banner(%{assigns: %{user: user}} = conn, params) do
|
||||||
{:ok, user} <- User.update_and_set_cache(change) do
|
{:ok, user} <- User.update_and_set_cache(change) do
|
||||||
CommonAPI.update(user)
|
CommonAPI.update(user)
|
||||||
%{"url" => [ %{ "href" => href } | _ ]} = object.data
|
%{"url" => [ %{ "href" => href } | _ ]} = object.data
|
||||||
response = %{ url: href } |> Poison.encode!
|
response = %{ url: href } |> Jason.encode!
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
end
|
end
|
||||||
|
@ -232,7 +232,7 @@ def update_background(%{assigns: %{user: user}} = conn, params) do
|
||||||
change <- User.info_changeset(user, %{info: new_info}),
|
change <- User.info_changeset(user, %{info: new_info}),
|
||||||
{:ok, _user} <- User.update_and_set_cache(change) do
|
{:ok, _user} <- User.update_and_set_cache(change) do
|
||||||
%{"url" => [ %{ "href" => href } | _ ]} = object.data
|
%{"url" => [ %{ "href" => href } | _ ]} = object.data
|
||||||
response = %{ url: href } |> Poison.encode!
|
response = %{ url: href } |> Jason.encode!
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
end
|
end
|
||||||
|
@ -240,7 +240,7 @@ def update_background(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
|
||||||
def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" => uri}) do
|
def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" => uri}) do
|
||||||
with {:ok, user_map} <- TwitterAPI.get_external_profile(current_user, uri),
|
with {:ok, user_map} <- TwitterAPI.get_external_profile(current_user, uri),
|
||||||
response <- Poison.encode!(user_map) do
|
response <- Jason.encode!(user_map) do
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
else
|
else
|
||||||
|
@ -259,7 +259,7 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
|
||||||
changeset <- User.info_changeset(user, %{info: updated_info}),
|
changeset <- User.info_changeset(user, %{info: updated_info}),
|
||||||
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, Poison.encode!(mrn))
|
|> json_reply(200, Jason.encode!(mrn))
|
||||||
else
|
else
|
||||||
_e -> bad_request_reply(conn, "Can't update.")
|
_e -> bad_request_reply(conn, "Can't update.")
|
||||||
end
|
end
|
||||||
|
@ -287,7 +287,7 @@ def friends_ids(%{assigns: %{user: user}} = conn, _params) do
|
||||||
with {:ok, friends} <- User.get_friends(user) do
|
with {:ok, friends} <- User.get_friends(user) do
|
||||||
ids = friends
|
ids = friends
|
||||||
|> Enum.map(fn x -> x.id end)
|
|> Enum.map(fn x -> x.id end)
|
||||||
|> Poison.encode!
|
|> Jason.encode!
|
||||||
|
|
||||||
json(conn, ids)
|
json(conn, ids)
|
||||||
else
|
else
|
||||||
|
@ -296,7 +296,7 @@ def friends_ids(%{assigns: %{user: user}} = conn, _params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty_array(conn, _params) do
|
def empty_array(conn, _params) do
|
||||||
json(conn, Poison.encode!([]))
|
json(conn, Jason.encode!([]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
@ -339,6 +339,6 @@ defp forbidden_json_reply(conn, error_message) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp error_json(conn, error_message) do
|
defp error_json(conn, error_message) do
|
||||||
%{"error" => error_message, "request" => conn.request_path} |> Poison.encode!
|
%{"error" => error_message, "request" => conn.request_path} |> Jason.encode!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule Pleroma.Web.WebFinger do
|
||||||
alias Pleroma.{Repo, User, XmlBuilder}
|
alias Pleroma.{Repo, User, XmlBuilder}
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.{XML, Salmon, OStatus}
|
alias Pleroma.Web.{XML, Salmon, OStatus}
|
||||||
require Poison
|
require Jason
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def host_meta do
|
def host_meta do
|
||||||
|
@ -182,7 +182,7 @@ def finger(account) do
|
||||||
if doc != :error do
|
if doc != :error do
|
||||||
webfinger_from_xml(doc)
|
webfinger_from_xml(doc)
|
||||||
else
|
else
|
||||||
{:ok, doc} = Poison.decode(body)
|
{:ok, doc} = Jason.decode(body)
|
||||||
webfinger_from_json(doc)
|
webfinger_from_json(doc)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue