Merge remote-tracking branch 'origin/develop' into shigusegubu

This commit is contained in:
SGSGB 2018-08-29 21:56:22 +02:00
commit 5379db3194
6 changed files with 32 additions and 37 deletions

View file

@ -8,8 +8,6 @@ defmodule Pleroma.Activity do
field(:local, :boolean, default: true) field(:local, :boolean, default: true)
field(:actor, :string) field(:actor, :string)
field(:recipients, {:array, :string}) field(:recipients, {:array, :string})
field(:recipients_to, {:array, :string})
field(:recipients_cc, {:array, :string})
has_many(:notifications, Notification, on_delete: :delete_all) has_many(:notifications, Notification, on_delete: :delete_all)
timestamps() timestamps()

View file

@ -60,16 +60,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
:ok <- check_actor_is_active(map["actor"]), :ok <- check_actor_is_active(map["actor"]),
{:ok, map} <- MRF.filter(map), {:ok, map} <- MRF.filter(map),
:ok <- insert_full_object(map) do :ok <- insert_full_object(map) do
{recipients, recipients_to, recipients_cc} = get_recipients(map) {recipients, _, _} = get_recipients(map)
{:ok, activity} = {:ok, activity} =
Repo.insert(%Activity{ Repo.insert(%Activity{
data: map, data: map,
local: local, local: local,
actor: map["actor"], actor: map["actor"],
recipients: recipients, recipients: recipients
recipients_to: recipients_to,
recipients_cc: recipients_cc
}) })
Notification.create_notifications(activity) Notification.create_notifications(activity)
@ -415,11 +413,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
activity in query, activity in query,
where: where:
fragment( fragment(
"(? && ?) or (? && ?)", "(?->'to' \\?| ?) or (?->'cc' \\?| ?)",
activity.data,
^recipients_to, ^recipients_to,
activity.recipients_to, activity.data,
^recipients_cc, ^recipients_cc
activity.recipients_cc
) )
) )
end end

View file

@ -28,7 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
%{ %{
id: to_string(user.id), id: to_string(user.id),
username: hd(String.split(user.nickname, "@")), username: username_from_nickname(user.nickname),
acct: user.nickname, acct: user.nickname,
display_name: user.name || user.nickname, display_name: user.name || user.nickname,
locked: user_info.locked, locked: user_info.locked,
@ -56,7 +56,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
%{ %{
id: to_string(user.id), id: to_string(user.id),
acct: user.nickname, acct: user.nickname,
username: hd(String.split(user.nickname, "@")), username: username_from_nickname(user.nickname),
url: user.ap_id url: user.ap_id
} }
end end
@ -76,4 +76,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
def render("relationships.json", %{user: user, targets: targets}) do def render("relationships.json", %{user: user, targets: targets}) do
render_many(targets, AccountView, "relationship.json", user: user, as: :target) render_many(targets, AccountView, "relationship.json", user: user, as: :target)
end end
defp username_from_nickname(string) when is_binary(string) do
hd(String.split(string, "@"))
end
defp username_from_nickname(_), do: nil
end end

View file

@ -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

View file

@ -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

View file

@ -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