Ensure we capture the application details into the object

This commit is contained in:
Mark Felder 2021-02-09 18:07:15 -06:00
parent de8b8e9cf1
commit 3dc7e89c54
2 changed files with 17 additions and 4 deletions

View File

@ -190,6 +190,7 @@ defp object(draft) do
Utils.make_note_data(draft) Utils.make_note_data(draft)
|> Map.put("emoji", emoji) |> Map.put("emoji", emoji)
|> Map.put("source", draft.status) |> Map.put("source", draft.status)
|> Map.put("application", draft.params[:application])
%__MODULE__{draft | object: object} %__MODULE__{draft | object: object}
end end

View File

@ -132,13 +132,15 @@ 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}, assigns: %{user: user, token: %{app_id: app_id}},
body_params: %{status: _, scheduled_at: scheduled_at} = params body_params: %{status: _, scheduled_at: scheduled_at} = params
} = conn, } = conn,
_ _
) )
when not is_nil(scheduled_at) do when not is_nil(scheduled_at) do
params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id]) params =
Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
|> add_application(app_id)
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),
@ -161,8 +163,14 @@ def create(
end end
# Creates a regular status # Creates a regular status
def create(%{assigns: %{user: user}, body_params: %{status: _} = params} = conn, _) do def create(
params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id]) %{assigns: %{user: user, token: %{app_id: app_id}}, body_params: %{status: _} = params} =
conn,
_
) do
params =
Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
|> add_application(app_id)
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",
@ -414,4 +422,8 @@ def bookmarks(%{assigns: %{user: user}} = conn, params) do
as: :activity as: :activity
) )
end end
defp add_application(params, app_id) do
params |> Map.put(:application, Pleroma.Web.OAuth.App.get_app_by_id(app_id))
end
end end