with nil <- Activity.get_by_ap_id(map["id"]),
map <- lazy_put_activity_defaults(map),
:ok <- insert_full_object(map) do
- {:ok, activity} = Repo.insert(%Activity{data: map, local: local})
+ {:ok, activity} = Repo.insert(%Activity{data: map, local: local, actor: map["actor"]})
Notification.create_notifications(activity)
{:ok, activity}
else
defp restrict_actor(query, %{"actor_id" => actor_id}) do
from activity in query,
- where: fragment("?->>'actor' = ?", activity.data, ^actor_id)
+ where: activity.actor == ^actor_id
end
defp restrict_actor(query, _), do: query
defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
blocks = info["blocks"] || []
from activity in query,
- where: fragment("not (?->>'actor' = ANY(?))", activity.data, ^blocks)
+ where: fragment("not (? = ANY(?))", activity.actor, ^blocks)
end
defp restrict_blocked(query, _), do: query
def fetch_activities(recipients, opts \\ %{}) do
base_query = from activity in Activity,
limit: 20,
- order_by: [desc: :id]
+ order_by: [fragment("? desc nulls last", activity.id)]
base_query
|> restrict_recipients(recipients)
--- /dev/null
+defmodule Pleroma.Repo.Migrations.AddActorToActivity do
+ use Ecto.Migration
+
+ @disable_ddl_transaction true
+
+ def up do
+ alter table(:activities) do
+ add :actor, :string
+ end
+
+ execute """
+ update activities set actor = data->>'actor';
+ """
+
+ create index(:activities, [:actor, "id DESC NULLS LAST"], concurrently: true)
+ end
+
+ def down do
+ drop index(:activities, [:actor, "id DESC NULLS LAST"])
+ alter table(:activities) do
+ remove :actor
+ end
+ end
+end
test "removes doubled 'to' recipients" do
{:ok, activity} = ActivityPub.create(["user1", "user1", "user2"], %User{ap_id: "1"}, "", %{})
assert activity.data["to"] == ["user1", "user2"]
+ assert activity.actor == "1"
end
end