Merge remote-tracking branch 'origin/develop' into shigusegubu
This commit is contained in:
commit
5379db3194
6 changed files with 32 additions and 37 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -415,11 +413,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue