X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity%2Fqueries.ex;h=4632651b026da07cbf4ff66b434531d2cb13d2e2;hb=e28d990ecba287d5c44ed04c0039b43c8f309e50;hp=633eca0b31095b3a8a03609bc71e3cd8597c32db;hpb=c29ad60c2014069929bc2906aa3af106a04ef215;p=akkoma
diff --git a/lib/pleroma/activity/queries.ex b/lib/pleroma/activity/queries.ex
index 633eca0b3..4632651b0 100644
--- a/lib/pleroma/activity/queries.ex
+++ b/lib/pleroma/activity/queries.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Activity.Queries do
@@ -14,6 +14,11 @@ defmodule Pleroma.Activity.Queries do
alias Pleroma.Activity
alias Pleroma.User
+ @spec by_id(query(), String.t()) :: query()
+ def by_id(query \\ Activity, id) do
+ from(a in query, where: a.id == ^id)
+ end
+
@spec by_ap_id(query, String.t()) :: query
def by_ap_id(query \\ Activity, ap_id) do
from(
@@ -32,6 +37,13 @@ defmodule Pleroma.Activity.Queries do
from(a in query, where: a.actor == ^ap_id)
end
+ def find_by_object_ap_id(activities, object_ap_id) do
+ Enum.find(
+ activities,
+ &(object_ap_id in [is_map(&1.data["object"]) && &1.data["object"]["id"], &1.data["object"]])
+ )
+ end
+
@spec by_object_id(query, String.t() | [String.t()]) :: query
def by_object_id(query \\ Activity, object_id)