From ddc6f32b757c3d99cf1d1cf40c15d126f40145db Mon Sep 17 00:00:00 2001 From: href Date: Wed, 29 Aug 2018 16:26:36 +0200 Subject: [PATCH 1/5] Fix Mastodon API when actor's nickname is null --- lib/pleroma/web/mastodon_api/views/account_view.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index d9edcae7f..133cae3b5 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -28,7 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do %{ id: to_string(user.id), - username: hd(String.split(user.nickname, "@")), + username: username_from_nickname(user.nickname), acct: user.nickname, display_name: user.name || user.nickname, locked: user_info.locked, @@ -56,7 +56,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do %{ id: to_string(user.id), acct: user.nickname, - username: hd(String.split(user.nickname, "@")), + username: username_from_nickname(user.nickname), url: user.ap_id } end @@ -76,4 +76,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do def render("relationships.json", %{user: user, targets: targets}) do render_many(targets, AccountView, "relationship.json", user: user, as: :target) end + + defp username_from_nickname(string) when is_binary(string) do + hd(String.split(string, "@")) + end + + defp username_from_nickname(_), do: nil end From de9acebbf39ca397d9388b12b167b55110611fa6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 29 Aug 2018 18:32:04 +0000 Subject: [PATCH 2/5] activitypub: use jsonb query for containment instead of recipients_to/recipients_cc. --- lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index dad9c4865..116dbcf1e 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -415,11 +415,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do activity in query, where: fragment( - "(? && ?) or (? && ?)", + "(?->'to' \\?| ?) or (?->'cc' \\?| ?)", + activity.data, ^recipients_to, - activity.recipients_to, - ^recipients_cc, - activity.recipients_cc + activity.data, + ^recipients_cc ) ) end From 038139d64158f3362385c89964c6b9b1dc08b6b1 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 29 Aug 2018 18:33:09 +0000 Subject: [PATCH 3/5] migrations: drop filler migration --- ...ipients_to_and_cc_fields_in_activities.exs | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 priv/repo/migrations/20180829082743_fill_recipients_to_and_cc_fields_in_activities.exs diff --git a/priv/repo/migrations/20180829082743_fill_recipients_to_and_cc_fields_in_activities.exs b/priv/repo/migrations/20180829082743_fill_recipients_to_and_cc_fields_in_activities.exs deleted file mode 100644 index 92ac39b94..000000000 --- a/priv/repo/migrations/20180829082743_fill_recipients_to_and_cc_fields_in_activities.exs +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Pleroma.Repo.Migrations.FillRecipientsToAndCcFieldsInActivities do - use Ecto.Migration - alias Pleroma.{Repo, Activity} - - def up do - max = Repo.aggregate(Activity, :max, :id) - if max do - IO.puts("#{max} activities") - chunks = 0..(round(max / 10_000)) - - Enum.each(chunks, fn (i) -> - min = i * 10_000 - max = min + 10_000 - execute(""" - update activities set recipients_to = array(select jsonb_array_elements_text(data->'to')) where id > #{min} and id <= #{max} and jsonb_typeof(data->'to') = 'array'; - """) - |> IO.inspect - execute(""" - update activities set recipients_cc = array(select jsonb_array_elements_text(data->'cc')) where id > #{min} and id <= #{max} and jsonb_typeof(data->'cc') = 'array'; - """) - |> IO.inspect - end) - end - end -end From 29b5e30c465ccb29465156d66eba02e6c0ef846f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 29 Aug 2018 18:38:30 +0000 Subject: [PATCH 4/5] activity: drop recipients_to/recipients_cc fields --- lib/pleroma/activity.ex | 2 -- lib/pleroma/web/activity_pub/activity_pub.ex | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 4f1f8292d..bed96861f 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -8,8 +8,6 @@ defmodule Pleroma.Activity do field(:local, :boolean, default: true) field(:actor, :string) field(:recipients, {:array, :string}) - field(:recipients_to, {:array, :string}) - field(:recipients_cc, {:array, :string}) has_many(:notifications, Notification, on_delete: :delete_all) timestamps() diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 116dbcf1e..e6c2dc9cf 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -60,16 +60,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do :ok <- check_actor_is_active(map["actor"]), {:ok, map} <- MRF.filter(map), :ok <- insert_full_object(map) do - {recipients, recipients_to, recipients_cc} = get_recipients(map) + {recipients, _, _} = get_recipients(map) {:ok, activity} = Repo.insert(%Activity{ data: map, local: local, actor: map["actor"], - recipients: recipients, - recipients_to: recipients_to, - recipients_cc: recipients_cc + recipients: recipients }) Notification.create_notifications(activity) From 1a70d41f8e7ce0eb30242d58077b69816e443c10 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 29 Aug 2018 18:38:51 +0000 Subject: [PATCH 5/5] migrations: add index creation migration and recipients_to/cc removal migration --- .../20180829182612_activities_add_to_cc_indices.exs | 8 ++++++++ ...ove_recipients_to_and_cc_fields_from_activities.exs | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs create mode 100644 priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs diff --git a/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs b/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs new file mode 100644 index 000000000..f6c622e3e --- /dev/null +++ b/priv/repo/migrations/20180829182612_activities_add_to_cc_indices.exs @@ -0,0 +1,8 @@ +defmodule Pleroma.Repo.Migrations.ActivitiesAddToCcIndices do + use Ecto.Migration + + def change do + create index(:activities, ["(data->'to')"], name: :activities_to_index, using: :gin) + create index(:activities, ["(data->'cc')"], name: :activities_cc_index, using: :gin) + end +end diff --git a/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs b/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs new file mode 100644 index 000000000..ed4f5af30 --- /dev/null +++ b/priv/repo/migrations/20180829183529_remove_recipients_to_and_cc_fields_from_activities.exs @@ -0,0 +1,10 @@ +defmodule Pleroma.Repo.Migrations.RemoveRecipientsToAndCcFieldsFromActivities do + use Ecto.Migration + + def change do + alter table(:activities) do + remove :recipients_to + remove :recipients_cc + end + end +end