mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 11:19:19 +00:00
activity: add recipients_to and recipients_cc fields
This commit is contained in:
parent
0fd2eaf7af
commit
81673b8136
3 changed files with 31 additions and 5 deletions
|
@ -8,6 +8,8 @@ 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()
|
||||||
|
|
|
@ -14,8 +14,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|
|
||||||
# For Announce activities, we filter the recipients based on following status for any actors
|
# For Announce activities, we filter the recipients based on following status for any actors
|
||||||
# that match actual users. See issue #164 for more information about why this is necessary.
|
# that match actual users. See issue #164 for more information about why this is necessary.
|
||||||
def get_recipients(%{"type" => "Announce"} = data) do
|
defp get_recipients(%{"type" => "Announce"} = data) do
|
||||||
recipients = (data["to"] || []) ++ (data["cc"] || [])
|
to = data["to"] || []
|
||||||
|
cc = data["cc"] || []
|
||||||
|
recipients = to ++ cc
|
||||||
actor = User.get_cached_by_ap_id(data["actor"])
|
actor = User.get_cached_by_ap_id(data["actor"])
|
||||||
|
|
||||||
recipients
|
recipients
|
||||||
|
@ -28,10 +30,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
User.following?(user, actor)
|
User.following?(user, actor)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
{recipients, to, cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_recipients(data) do
|
defp get_recipients(data) do
|
||||||
(data["to"] || []) ++ (data["cc"] || [])
|
to = data["to"] || []
|
||||||
|
cc = data["cc"] || []
|
||||||
|
recipients = to ++ cc
|
||||||
|
{recipients, to, cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_actor_is_active(actor) do
|
defp check_actor_is_active(actor) do
|
||||||
|
@ -53,12 +60,16 @@ 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)
|
||||||
|
|
||||||
{: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: get_recipients(map)
|
recipients: recipients,
|
||||||
|
recipients_to: recipients_to,
|
||||||
|
recipients_cc: recipients_cc
|
||||||
})
|
})
|
||||||
|
|
||||||
Notification.create_notifications(activity)
|
Notification.create_notifications(activity)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddRecipientsToAndCcFieldsToActivities do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:activities) do
|
||||||
|
add :recipients_to, {:array, :string}
|
||||||
|
add :recipients_cc, {:array, :string}
|
||||||
|
end
|
||||||
|
|
||||||
|
create index(:activities, [:recipients_to], using: :gin)
|
||||||
|
create index(:activities, [:recipients_cc], using: :gin)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue