+ def get_notified_from_activity_query(to, false) do
+ from(
+ u in User,
+ where: u.ap_id in ^to
+ )
+ end
+
+ def get_notified_from_activity_query(to, true) do
+ query = get_notified_from_activity_query(to, false)
+
+ from(
+ u in query,
+ where: u.local == true
+ )
+ end
+
+ def get_notified_from_activity(activity, local_only \\ true)
+
+ def get_notified_from_activity(
+ %Activity{data: %{"type" => "Announce", "to" => to} = data},
+ local_only
+ ) do
+ object = Object.normalize(data["object"])
+ actor = User.get_cached_by_ap_id(data["actor"])
+
+ # ensure that the actor who published the announced object appears only once
+ to =
+ if actor.nickname != nil do
+ to ++ [object.data["actor"]]
+ else
+ to
+ end
+ |> Enum.uniq()
+
+ query = get_notified_from_activity_query(to, local_only)