%Token{} may not be in the conn, so avoid breaking the ability to post statuses in that scenario.
This commit is contained in:
parent
4540e08a6a
commit
09b8378646
|
@ -132,7 +132,7 @@ def index(%{assigns: %{user: user}} = conn, %{ids: ids} = params) do
|
||||||
# Creates a scheduled status when `scheduled_at` param is present and it's far enough
|
# Creates a scheduled status when `scheduled_at` param is present and it's far enough
|
||||||
def create(
|
def create(
|
||||||
%{
|
%{
|
||||||
assigns: %{user: user, token: %{app_id: app_id}},
|
assigns: %{user: user},
|
||||||
body_params: %{status: _, scheduled_at: scheduled_at} = params
|
body_params: %{status: _, scheduled_at: scheduled_at} = params
|
||||||
} = conn,
|
} = conn,
|
||||||
_
|
_
|
||||||
|
@ -140,7 +140,7 @@ def create(
|
||||||
when not is_nil(scheduled_at) do
|
when not is_nil(scheduled_at) do
|
||||||
params =
|
params =
|
||||||
Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
||||||
|> add_application(app_id)
|
|> add_application(conn)
|
||||||
|
|
||||||
attrs = %{
|
attrs = %{
|
||||||
params: Map.new(params, fn {key, value} -> {to_string(key), value} end),
|
params: Map.new(params, fn {key, value} -> {to_string(key), value} end),
|
||||||
|
@ -164,13 +164,12 @@ def create(
|
||||||
|
|
||||||
# Creates a regular status
|
# Creates a regular status
|
||||||
def create(
|
def create(
|
||||||
%{assigns: %{user: user, token: %{app_id: app_id}}, body_params: %{status: _} = params} =
|
%{assigns: %{user: user}, body_params: %{status: _} = params} = conn,
|
||||||
conn,
|
|
||||||
_
|
_
|
||||||
) do
|
) do
|
||||||
params =
|
params =
|
||||||
Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
||||||
|> add_application(app_id)
|
|> add_application(conn)
|
||||||
|
|
||||||
with {:ok, activity} <- CommonAPI.post(user, params) do
|
with {:ok, activity} <- CommonAPI.post(user, params) do
|
||||||
try_render(conn, "show.json",
|
try_render(conn, "show.json",
|
||||||
|
@ -423,7 +422,9 @@ def bookmarks(%{assigns: %{user: user}} = conn, params) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_application(params, app_id) do
|
defp add_application(params, %{assigns: %{token: %{app_id: app_id}}} = _conn) do
|
||||||
params |> Map.put(:application, Pleroma.Web.OAuth.App.get_app_by_id(app_id))
|
params |> Map.put(:application, Pleroma.Web.OAuth.App.get_app_by_id(app_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp add_application(params, _), do: Map.put(params, :application, %{name: "Web", website: nil})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue