activity: add recipient_users column
This commit is contained in:
parent
ba36288b8b
commit
cb3772f0ce
|
@ -39,6 +39,7 @@ defmodule Pleroma.Activity do
|
||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
field(:actor, :string)
|
field(:actor, :string)
|
||||||
field(:recipients, {:array, :string}, default: [])
|
field(:recipients, {:array, :string}, default: [])
|
||||||
|
field(:recipient_users, {:array, :string}, default: [])
|
||||||
field(:thread_muted?, :boolean, virtual: true)
|
field(:thread_muted?, :boolean, virtual: true)
|
||||||
# This is a fake relation, do not use outside of with_preloaded_bookmark/get_bookmark
|
# This is a fake relation, do not use outside of with_preloaded_bookmark/get_bookmark
|
||||||
has_one(:bookmark, Bookmark)
|
has_one(:bookmark, Bookmark)
|
||||||
|
|
|
@ -61,6 +61,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
{recipients, to, cc}
|
{recipients, to, cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_recipient_users(recipients),
|
||||||
|
do: Enum.filter(recipients, fn recipient -> !is_nil(User.get_cached_by_ap_id(recipient)) end)
|
||||||
|
|
||||||
defp check_actor_is_active(actor) do
|
defp check_actor_is_active(actor) do
|
||||||
if not is_nil(actor) do
|
if not is_nil(actor) do
|
||||||
with user <- User.get_cached_by_ap_id(actor),
|
with user <- User.get_cached_by_ap_id(actor),
|
||||||
|
@ -126,6 +129,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
{_, true} <- {:remote_limit_error, check_remote_limit(map)},
|
{_, true} <- {:remote_limit_error, check_remote_limit(map)},
|
||||||
{:ok, map} <- MRF.filter(map),
|
{:ok, map} <- MRF.filter(map),
|
||||||
{recipients, _, _} = get_recipients(map),
|
{recipients, _, _} = get_recipients(map),
|
||||||
|
recipient_users <- get_recipient_users(recipients),
|
||||||
{:fake, false, map, recipients} <- {:fake, fake, map, recipients},
|
{:fake, false, map, recipients} <- {:fake, fake, map, recipients},
|
||||||
:ok <- Containment.contain_child(map),
|
:ok <- Containment.contain_child(map),
|
||||||
{:ok, map, object} <- insert_full_object(map) do
|
{:ok, map, object} <- insert_full_object(map) do
|
||||||
|
@ -134,7 +138,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
data: map,
|
data: map,
|
||||||
local: local,
|
local: local,
|
||||||
actor: map["actor"],
|
actor: map["actor"],
|
||||||
recipients: recipients
|
recipients: recipients,
|
||||||
|
recipient_users: recipient_users
|
||||||
})
|
})
|
||||||
|
|
||||||
# Splice in the child object if we have one.
|
# Splice in the child object if we have one.
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddRecipientUsersToActivities do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:activities) do
|
||||||
|
add :recipient_users, {:array, :string}
|
||||||
|
end
|
||||||
|
|
||||||
|
create_if_not_exists index(:activities, [:recipient_users], using: :gin)
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
import Mock
|
import Mock
|
||||||
|
|
||||||
|
require Pleroma.Constants
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
:ok
|
:ok
|
||||||
|
@ -278,6 +280,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
assert activity.recipients == ["user1", "user2", user.ap_id]
|
assert activity.recipients == ["user1", "user2", user.ap_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "recipient_users only contains AP IDs of actual users" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
ActivityPub.create(%{
|
||||||
|
to: [Pleroma.Constants.as_public(), user.ap_id],
|
||||||
|
actor: user,
|
||||||
|
context: "",
|
||||||
|
object: %{
|
||||||
|
"to" => [Pleroma.Constants.as_public(), user.ap_id],
|
||||||
|
"type" => "Note",
|
||||||
|
"content" => "testing"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
assert activity.recipient_users == [user.ap_id]
|
||||||
|
end
|
||||||
|
|
||||||
test "increases user note count only for public activities" do
|
test "increases user note count only for public activities" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue