diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index f8a03680a..cfb36bc1c 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -461,8 +461,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec update(User.t(), Activity.t(), map()) :: {:ok, Activity.t()} | {:error, any()} - def update(user, orig_activity, changes) do + @spec update(Activity.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} + def update(orig_activity, %User{} = user, changes) do with orig_object <- Object.normalize(orig_activity), {:ok, new_object} <- make_update_data(user, orig_object, changes), {:ok, update_data, _} <- Builder.update(user, new_object), diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 80386dc45..f75efd00d 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -276,7 +276,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do actor <- Activity.user_actor(activity), {_, true} <- {:own_status, actor.id == user.id}, changes <- body_params |> put_application(conn), - {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(user, activity, changes)}, + {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(activity, user, changes)}, {_, %Activity{}} = {_, activity} <- {:refetched, Activity.get_by_id_with_object(id)} do try_render(conn, "show.json", activity: activity, diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index a0ffddf8d..49edeb91e 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -440,7 +440,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do assert_receive {:text, _raw_json}, 1_000 - {:ok, _} = CommonAPI.update(user, activity, %{status: "mew mew", visibility: "private"}) + {:ok, _} = CommonAPI.update(activity, user, %{status: "mew mew", visibility: "private"}) assert_receive {:text, raw_json}, 1_000 diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index e9923cb56..c7ed18bba 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -165,7 +165,7 @@ defmodule Pleroma.NotificationTest do {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, _edit_activity} = - CommonAPI.update(user, activity_one, %{ + CommonAPI.update(activity_one, user, %{ status: "hey @#{other_user.nickname}! mew mew" }) @@ -748,7 +748,7 @@ defmodule Pleroma.NotificationTest do {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, edit_activity} = - CommonAPI.update(user, activity_one, %{ + CommonAPI.update(activity_one, user, %{ status: "hey @#{other_user.nickname}! mew mew" }) diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index 2b33950d6..e1dbb20c3 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -43,7 +43,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest setup do user = insert(:user) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) - {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) + {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"}) {:ok, %{"object" => external_rep}} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) diff --git a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs index a09dbf5c6..c88339d14 100644 --- a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs @@ -132,7 +132,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do setup do user = insert(:user) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) - {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) + {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"}) {:ok, external_rep} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) %{external_rep: external_rep} end diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 2fb0cd079..6da7e4a89 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -353,7 +353,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"}) - {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew :blank:"}) + {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew :blank:"}) {:ok, prepared} = Transmogrifier.prepare_outgoing(update.data) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 4f3bc6921..433278d39 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1753,7 +1753,7 @@ defmodule Pleroma.Web.CommonAPITest do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2" @@ -1767,7 +1767,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1", visibility: "private"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2" @@ -1784,7 +1784,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2 :#{emoji2}:" @@ -1803,7 +1803,7 @@ defmodule Pleroma.Web.CommonAPITest do with_mock Pleroma.Web.Federator, publish: fn _p -> nil end do - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"}) assert updated.data["object"]["content"] == "updated 2 :#{emoji2}:" assert %{^emoji2 => _} = updated.data["object"]["emoji"] @@ -1847,7 +1847,7 @@ defmodule Pleroma.Web.CommonAPITest do assert reply.object.data["emoji"]["remoteemoji"] == remote_emoji_uri {:ok, edit} = - CommonAPI.update(user, reply, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) + CommonAPI.update(reply, user, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) edited_note = Pleroma.Object.normalize(edit) @@ -1863,7 +1863,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "updated 1"}) assert Object.normalize(activity).data["summary"] == "mewmew 1" - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "mewmew 2" diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 003ac8c36..3ad5e1606 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -290,7 +290,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do {:ok, activity} = CommonAPI.post(user, %{status: "mew"}) {:ok, _} = CommonAPI.repeat(activity.id, repeat_user) - {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew"}) + {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew"}) user = Pleroma.User.get_by_ap_id(user.ap_id) activity = Pleroma.Activity.normalize(activity) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index f42d9d1c6..cfcb8cfb2 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -938,7 +938,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do status = StatusView.render("show.json", activity: post) refute status.edited_at - {:ok, _} = CommonAPI.update(poster, post, %{status: "mew mew"}) + {:ok, _} = CommonAPI.update(post, poster, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(post) status = StatusView.render("show.json", activity: edited) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 9bc02dadf..f986d3fd5 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -81,7 +81,7 @@ defmodule Pleroma.Web.Metadata.UtilsTest do object = Pleroma.Object.normalize(activity) assert Utils.scrub_html_and_truncate(object) == "mew mew #def" - {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"}) + {:ok, update} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "mew mew #abc"}) update = Pleroma.Activity.normalize(update) object = Pleroma.Object.normalize(update) assert Utils.scrub_html_and_truncate(object) == "mew mew #abc" diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index 5e2b20ab5..dcd909f1c 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -225,7 +225,7 @@ defmodule Pleroma.Web.Push.ImplTest do {:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"}) - {:ok, activity} = CommonAPI.update(user, activity, %{status: "edited status"}) + {:ok, activity} = CommonAPI.update(activity, user, %{status: "edited status"}) object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "update"}, user, object) == diff --git a/test/pleroma/web/rich_media/card_test.exs b/test/pleroma/web/rich_media/card_test.exs index 9541627c1..387defc8c 100644 --- a/test/pleroma/web/rich_media/card_test.exs +++ b/test/pleroma/web/rich_media/card_test.exs @@ -70,7 +70,7 @@ defmodule Pleroma.Web.RichMedia.CardTest do Card.get_by_activity(activity) ) - {:ok, _} = CommonAPI.update(user, activity, %{status: "I like this site #{updated_url}"}) + {:ok, _} = CommonAPI.update(activity, user, %{status: "I like this site #{updated_url}"}) activity = Pleroma.Activity.get_by_id(activity.id) diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index 978e8a823..e53c6adc4 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -541,7 +541,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) Streamer.get_topic_and_add_socket("user", user, oauth_token) - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) assert_receive {:render_with_user, _, "status_update.json", ^create, _} @@ -552,7 +552,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) Streamer.get_topic_and_add_socket("user", user, oauth_token) - {:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, user, %{status: "mew mew"}) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) assert_receive {:render_with_user, _, "status_update.json", ^create, _} @@ -608,7 +608,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) assert_receive {:text, _} - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(edited) @@ -627,7 +627,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) assert_receive {:text, _} - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(edited) @@ -638,7 +638,7 @@ defmodule Pleroma.Web.StreamerTest do assert %{"id" => ^activity_id} = Jason.decode!(payload) refute Streamer.filtered_by_user?(sender, edited) - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew 2"}) edited = Pleroma.Activity.normalize(edited)