From b82c6dc53685ebd26c276eccc5ed915ddf81afa6 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:29:05 +0100 Subject: [PATCH 1/7] =?UTF-8?q?Activity:=20all=5Fby=5Fobject=5Fap=5Fid/1?= =?UTF-8?q?=20=E2=86=92=20get=5Fall=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 3 +-- lib/pleroma/web/activity_pub/utils.ex | 2 +- test/activity_test.exs | 2 +- test/web/activity_pub/activity_pub_test.exs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 353f9f6cd..e3edec475 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -67,8 +67,7 @@ defmodule Pleroma.Activity do ) end - # Wrong name plz fix thx - def all_by_object_ap_id(ap_id) do + def get_all_by_object_ap_id(ap_id) do Repo.all(all_by_object_ap_id_q(ap_id)) end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d2e457a68..cfbe6c857 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -198,7 +198,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do # Update activities that already had this. Could be done in a seperate process. # Alternatively, just don't do this and fetch the current object each time. Most # could probably be taken from cache. - relevant_activities = Activity.all_by_object_ap_id(id) + relevant_activities = Activity.get_all_by_object_ap_id(id) Enum.map(relevant_activities, fn activity -> new_activity_data = activity.data |> Map.put("object", object.data) diff --git a/test/activity_test.exs b/test/activity_test.exs index 36c718869..8f3f613ec 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -16,7 +16,7 @@ defmodule Pleroma.ActivityTest do test "returns activities by it's objects AP ids" do activity = insert(:note_activity) - [found_activity] = Activity.all_by_object_ap_id(activity.data["object"]["id"]) + [found_activity] = Activity.get_all_by_object_ap_id(activity.data["object"]["id"]) assert activity == found_activity end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index eafb96f3a..6538fb7af 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -330,7 +330,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert like_activity == same_like_activity assert object.data["likes"] == [user.ap_id] - [note_activity] = Activity.all_by_object_ap_id(object.data["id"]) + [note_activity] = Activity.get_all_by_object_ap_id(object.data["id"]) assert note_activity.data["object"]["like_count"] == 1 {:ok, _like_activity, object} = ActivityPub.like(user_two, object) From 75e4c8f0b21323f072f06e25e10762339abc6e3b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:15:05 +0100 Subject: [PATCH 2/7] =?UTF-8?q?Activity:=20all=5Fnon=5Fcreate=5Fby=5Fobjec?= =?UTF-8?q?t=5Fap=5Fid=5Fq=20=E2=86=92=20by=5Fobject=5Fap=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 3 +-- lib/pleroma/object.ex | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index e3edec475..3be6fb82b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -53,8 +53,7 @@ defmodule Pleroma.Activity do ) end - # Wrong name, returns all. - def all_non_create_by_object_ap_id_q(ap_id) do + def by_object_ap_id(ap_id) do from( activity in Activity, where: diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index ff5eb9b27..707a61f14 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -85,7 +85,7 @@ defmodule Pleroma.Object do def delete(%Object{data: %{"id" => id}} = object) do with {:ok, _obj} = swap_object_with_tombstone(object), - Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)), + Repo.delete_all(Activity.by_object_ap_id(id)), {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do {:ok, object} end From 4ad5a0abb99eb90b1b1bebbad79acc67c16cf945 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:39:00 +0100 Subject: [PATCH 3/7] =?UTF-8?q?Activity:=20all=5Fby=5Fobject=5Fap=5Fid=5Fq?= =?UTF-8?q?/1=20=E2=86=92=20create=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 3be6fb82b..588027de1 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -36,10 +36,7 @@ defmodule Pleroma.Activity do ) end - # TODO: - # Go through these and fix them everywhere. - # Wrong name, only returns create activities - def all_by_object_ap_id_q(ap_id) do + def create_by_object_ap_id(ap_id) do from( activity in Activity, where: @@ -67,7 +64,7 @@ defmodule Pleroma.Activity do end def get_all_by_object_ap_id(ap_id) do - Repo.all(all_by_object_ap_id_q(ap_id)) + Repo.all(create_by_object_ap_id(ap_id)) end def create_activity_by_object_id_query(ap_ids) do From f8ab1b7427e91ec1b7883e021836099226b56566 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:46:47 +0100 Subject: [PATCH 4/7] =?UTF-8?q?Activity:=20get=5Fall=5Fby=5Fobject=5Fap=5F?= =?UTF-8?q?id/1=20=E2=86=92=20get=5Fall=5Fcreate=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 8 ++++---- lib/pleroma/web/activity_pub/utils.ex | 2 +- test/activity_test.exs | 2 +- test/web/activity_pub/activity_pub_test.exs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 588027de1..8c73d1fa0 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -63,10 +63,6 @@ defmodule Pleroma.Activity do ) end - def get_all_by_object_ap_id(ap_id) do - Repo.all(create_by_object_ap_id(ap_id)) - end - def create_activity_by_object_id_query(ap_ids) do from( activity in Activity, @@ -81,6 +77,10 @@ defmodule Pleroma.Activity do ) end + def get_all_create_by_object_ap_id(ap_id) do + Repo.all(create_by_object_ap_id(ap_id)) + end + def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do create_activity_by_object_id_query([ap_id]) |> Repo.one() diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index cfbe6c857..4f4a54052 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -198,7 +198,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do # Update activities that already had this. Could be done in a seperate process. # Alternatively, just don't do this and fetch the current object each time. Most # could probably be taken from cache. - relevant_activities = Activity.get_all_by_object_ap_id(id) + relevant_activities = Activity.get_all_create_by_object_ap_id(id) Enum.map(relevant_activities, fn activity -> new_activity_data = activity.data |> Map.put("object", object.data) diff --git a/test/activity_test.exs b/test/activity_test.exs index 8f3f613ec..dcac8649a 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -16,7 +16,7 @@ defmodule Pleroma.ActivityTest do test "returns activities by it's objects AP ids" do activity = insert(:note_activity) - [found_activity] = Activity.get_all_by_object_ap_id(activity.data["object"]["id"]) + [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"]) assert activity == found_activity end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 6538fb7af..ea9ac5ba8 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -330,7 +330,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert like_activity == same_like_activity assert object.data["likes"] == [user.ap_id] - [note_activity] = Activity.get_all_by_object_ap_id(object.data["id"]) + [note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"]) assert note_activity.data["object"]["like_count"] == 1 {:ok, _like_activity, object} = ActivityPub.like(user_two, object) From 2fdbd4d137387d4d469d314b641070a9fdc0468c Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 07:07:54 +0100 Subject: [PATCH 5/7] =?UTF-8?q?Activity:=20create=5Factivity=5Fby=5Fobject?= =?UTF-8?q?=5Fid=5Fquery/1=20=E2=86=92=20create=5Fby=5Fobject=5Fap=5Fid/1?= =?UTF-8?q?=20when=20is=5Flist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 4 ++-- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 8c73d1fa0..5c3b8fcc5 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -63,7 +63,7 @@ defmodule Pleroma.Activity do ) end - def create_activity_by_object_id_query(ap_ids) do + def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do from( activity in Activity, where: @@ -82,7 +82,7 @@ defmodule Pleroma.Activity do end def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do - create_activity_by_object_id_query([ap_id]) + create_by_object_ap_id(ap_id) |> Repo.one() end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 7f5a52ea3..5e9c5c533 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do nil end) |> Enum.filter(& &1) - |> Activity.create_activity_by_object_id_query() + |> Activity.create_by_object_ap_id() |> Repo.all() |> Enum.reduce(%{}, fn activity, acc -> Map.put(acc, activity.data["object"]["id"], activity) From 98c8184c1fc013fbd48bd78a2603c8e560038081 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 07:14:20 +0100 Subject: [PATCH 6/7] =?UTF-8?q?Activity:=20get=5Fcreate=5Factivity=5Fby=5F?= =?UTF-8?q?object=5Fap=5Fid/1=20=E2=86=92=20get=5Fcreate=5Fby=5Fobject=5Fa?= =?UTF-8?q?p=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 35 ++++++++++--------- .../web/activity_pub/transmogrifier.ex | 4 +-- lib/pleroma/web/common_api/utils.ex | 4 +-- .../mastodon_api/mastodon_api_controller.ex | 11 +++--- .../web/mastodon_api/views/status_view.ex | 4 +-- .../web/ostatus/activity_representer.ex | 2 +- .../web/ostatus/handlers/note_handler.ex | 4 +-- lib/pleroma/web/ostatus/ostatus.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 3 +- lib/pleroma/web/twitter_api/twitter_api.ex | 8 ++--- .../web/twitter_api/twitter_api_controller.ex | 4 +-- .../web/twitter_api/views/activity_view.ex | 4 +-- test/activity_test.exs | 2 +- test/web/activity_pub/activity_pub_test.exs | 6 ++-- test/web/activity_pub/transmogrifier_test.exs | 6 ++-- test/web/mastodon_api/status_view_test.exs | 2 +- test/web/twitter_api/twitter_api_test.exs | 2 +- .../twitter_api/views/activity_view_test.exs | 2 +- 18 files changed, 52 insertions(+), 53 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 5c3b8fcc5..81079ec3e 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -36,20 +36,6 @@ defmodule Pleroma.Activity do ) end - def create_by_object_ap_id(ap_id) do - from( - activity in Activity, - where: - fragment( - "coalesce((?)->'object'->>'id', (?)->>'object') = ?", - activity.data, - activity.data, - ^to_string(ap_id) - ), - where: fragment("(?)->>'type' = 'Create'", activity.data) - ) - end - def by_object_ap_id(ap_id) do from( activity in Activity, @@ -63,6 +49,7 @@ defmodule Pleroma.Activity do ) end + def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do from( activity in Activity, @@ -77,23 +64,37 @@ defmodule Pleroma.Activity do ) end + def create_by_object_ap_id(ap_id) do + from( + activity in Activity, + where: + fragment( + "coalesce((?)->'object'->>'id', (?)->>'object') = ?", + activity.data, + activity.data, + ^to_string(ap_id) + ), + where: fragment("(?)->>'type' = 'Create'", activity.data) + ) + end + def get_all_create_by_object_ap_id(ap_id) do Repo.all(create_by_object_ap_id(ap_id)) end - def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do + def get_create_by_object_ap_id(ap_id) when is_binary(ap_id) do create_by_object_ap_id(ap_id) |> Repo.one() end - def get_create_activity_by_object_ap_id(_), do: nil + def get_create_by_object_ap_id(_), do: nil def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"]) def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id) def normalize(_), do: nil def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do - get_create_activity_by_object_ap_id(ap_id) + get_create_by_object_ap_id(ap_id) end def get_in_reply_to_activity(_), do: nil diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index fa3abe3d8..699a8957e 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -141,7 +141,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do case fetch_obj_helper(in_reply_to_id) do {:ok, replied_object} -> with %Activity{} = activity <- - Activity.get_create_activity_by_object_ap_id(replied_object.data["id"]) do + Activity.get_create_by_object_ap_id(replied_object.data["id"]) do object |> Map.put("inReplyTo", replied_object.data["id"]) |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id) @@ -334,7 +334,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do Map.put(data, "actor", actor) |> fix_addressing - with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]), + with nil <- Activity.get_create_by_object_ap_id(object["id"]), %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do object = fix_object(data["object"]) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index a36ab5c15..a0f59d900 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -14,13 +14,13 @@ defmodule Pleroma.Web.CommonAPI.Utils do # This is a hack for twidere. def get_by_id_or_ap_id(id) do - activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id) + activity = Repo.get(Activity, id) || Activity.get_create_by_object_ap_id(id) activity && if activity.data["type"] == "Create" do activity else - Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + Activity.get_create_by_object_ap_id(activity.data["object"]) end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 882d336be..f4736fcb5 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -377,7 +377,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -386,7 +386,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def fav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -395,7 +395,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def unfav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _, _, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -743,8 +743,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do fetched = if Regex.match?(~r/https?:/, query) do with {:ok, object} <- ActivityPub.fetch_object_from_id(query), - %Activity{} = activity <- - Activity.get_create_activity_by_object_ap_id(object.data["id"]), + %Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]), true <- ActivityPub.visible_for_user?(activity, user) do [activity] else @@ -1138,7 +1137,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do actor = User.get_cached_by_ap_id(activity.data["actor"]) - parent_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) mastodon_type = Activity.mastodon_notification_type(activity) response = %{ diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 5e9c5c533..74c875c29 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -64,7 +64,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do user = get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) - reblogged = Activity.get_create_activity_by_object_ap_id(object) + reblogged = Activity.get_create_by_object_ap_id(object) reblogged = render("status.json", Map.put(opts, :activity, reblogged)) mentions = @@ -209,7 +209,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def get_reply_to(%{data: %{"object" => object}}, _) do if object["inReplyTo"] && object["inReplyTo"] != "" do - Activity.get_create_activity_by_object_ap_id(object["inReplyTo"]) + Activity.get_create_by_object_ap_id(object["inReplyTo"]) else nil end diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 94b1a7ad1..3d41fc708 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -183,7 +183,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do _in_reply_to = get_in_reply_to(activity.data) author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] - retweeted_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"]) retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true) diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 5aeed46f0..c5b3e8d97 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do end def fetch_replied_to_activity(entry, inReplyTo) do - with %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(inReplyTo) do + with %Activity{} = activity <- Activity.get_create_by_object_ap_id(inReplyTo) do activity else _e -> @@ -103,7 +103,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do # TODO: Clean this up a bit. def handle_note(entry, doc \\ nil) do with id <- XML.string_from_xpath("//id", entry), - activity when is_nil(activity) <- Activity.get_create_activity_by_object_ap_id(id), + activity when is_nil(activity) <- Activity.get_create_by_object_ap_id(id), [author] <- :xmerl_xpath.string('//author[1]', doc), {:ok, actor} <- OStatus.find_make_or_update_user(author), content_html <- OStatus.get_content(entry), diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index bb28cd786..a3155b79d 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -148,7 +148,7 @@ defmodule Pleroma.Web.OStatus do Logger.debug("Trying to get entry from db") with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} else _ -> diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 332cbef0e..ce022bcc1 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -90,8 +90,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do ActivityPubController.call(conn, :object) else with id <- o_status_url(conn, :object, uuid), - {_, %Activity{} = activity} <- - {:activity, Activity.get_create_activity_by_object_ap_id(id)}, + {_, %Activity{} = activity} <- {:activity, Activity.get_create_by_object_ap_id(id)}, {_, true} <- {:public?, ActivityPub.is_public?(activity)}, %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case get_format(conn) do diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 7a63724f1..7d00c01a1 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -70,14 +70,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def repeat(%User{} = user, ap_id_or_id) do with {:ok, _announce, %{data: %{"id" => id}}} <- CommonAPI.repeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end def unrepeat(%User{} = user, ap_id_or_id) do with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end @@ -92,14 +92,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def fav(%User{} = user, ap_id_or_id) do with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end def unfav(%User{} = user, ap_id_or_id) do with {:ok, _unfav, _fav, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ede079963..8c9060cf2 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -330,12 +330,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def get_by_id_or_ap_id(id) do - activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id) + activity = Repo.get(Activity, id) || Activity.get_create_by_object_ap_id(id) if activity.data["type"] == "Create" do activity else - Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + Activity.get_create_by_object_ap_id(activity.data["object"]) end end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 03708d84c..5eb06a26e 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -168,7 +168,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activity} = opts) do user = get_user(activity.data["actor"], opts) created_at = activity.data["published"] |> Utils.date_to_asctime() - announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + announced_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) text = "#{user.nickname} retweeted a status." @@ -192,7 +192,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do user = get_user(activity.data["actor"], opts) - liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + liked_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) liked_activity_id = if liked_activity, do: liked_activity.id, else: nil created_at = diff --git a/test/activity_test.exs b/test/activity_test.exs index dcac8649a..ad889f544 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -24,7 +24,7 @@ defmodule Pleroma.ActivityTest do test "returns the activity that created an object" do activity = insert(:note_activity) - found_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"]) + found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"]) assert activity == found_activity end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index ea9ac5ba8..18f094379 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -216,7 +216,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, user} = User.block(user, %{ap_id: activity_three.data["actor"]}) {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster) - %Activity{} = boost_activity = Activity.get_create_activity_by_object_ap_id(id) + %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id) activity_three = Repo.get(Activity, activity_three.id) activities = ActivityPub.fetch_activities([], %{"blocking_user" => user}) @@ -445,7 +445,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, object} = ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367") - assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + assert activity = Activity.get_create_by_object_ap_id(object.data["id"]) assert activity.data["id"] {:ok, object_again} = @@ -459,7 +459,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do test "it works with objects only available via Ostatus" do {:ok, object} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873") - assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + assert activity = Activity.get_create_by_object_ap_id(object.data["id"]) assert activity.data["id"] {:ok, object_again} = diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 6107ac4f7..89e3dafd6 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -51,7 +51,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do {:ok, returned_activity} = Transmogrifier.handle_incoming(data) assert activity = - Activity.get_create_activity_by_object_ap_id( + Activity.get_create_by_object_ap_id( "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" ) @@ -263,7 +263,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["object"] == "http://mastodon.example.org/users/admin/statuses/99541947525187367" - assert Activity.get_create_activity_by_object_ap_id(data["object"]) + assert Activity.get_create_by_object_ap_id(data["object"]) end test "it works for incoming announces with an existing activity" do @@ -285,7 +285,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["object"] == activity.data["object"]["id"] - assert Activity.get_create_activity_by_object_ap_id(data["object"]).id == activity.id + assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id end test "it does not clobber the addressing on announce activities" do diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index d30ae6149..e33479368 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -202,7 +202,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" ) - %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"]) represented = StatusView.render("status.json", %{for: user, activity: activity}) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 547592ff2..f94e2b873 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -451,7 +451,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"] # Also fetches the feed. - # assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") + # assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") end end end diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 3d6b264b1..ba053d20d 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -344,7 +344,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" ) - %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"]) result = ActivityView.render("activity.json", activity: activity) From 7390192c03248ff18eff19d555f28300a7b07e09 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 07:37:45 +0100 Subject: [PATCH 7/7] Activity: mix format (2 empty lines) --- lib/pleroma/activity.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 81079ec3e..fe017df3b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -49,7 +49,6 @@ defmodule Pleroma.Activity do ) end - def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do from( activity in Activity,