end
end
+ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
+ user = User.get_cached_by_ap_id(actor)
+ data = %{
+ "type" => "Delete",
+ "actor" => actor,
+ "object" => id,
+ "to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"]
+ }
+ with Repo.delete(object),
+ Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
+ Repo.delete_all(Activity.all_by_object_ap_id_q(id)),
+ {:ok, activity} <- insert(data, local),
+ :ok <- maybe_federate(activity) do
+ {:ok, activity}
+ end
+ end
+
def fetch_activities_for_context(context) do
query = from activity in Activity,
- where: fragment("? @> ?", activity.data, ^%{ context: context })
+ where: fragment("? @> ?", activity.data, ^%{ type: "Create", context: context }),
+ order_by: [desc: :inserted_at]
Repo.all(query)
end
defp restrict_actor(query, %{"actor_id" => actor_id}) do
from activity in query,
- where: fragment("? @> ?", activity.data, ^%{actor: actor_id})
+ where: fragment("?->>'actor' = ?", activity.data, ^actor_id)
end
defp restrict_actor(query, _), do: query
def fetch_activities(recipients, opts \\ %{}) do
base_query = from activity in Activity,
limit: 20,
- order_by: [desc: :inserted_at]
+ order_by: [desc: :id]
base_query
|> restrict_recipients(recipients)