- with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
- {:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
+ actor = Containment.get_actor(data)
+
+ data =
+ Map.put(data, "actor", actor)
+ |> fix_addressing
+
+ with {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(data["actor"]) do
+ options = Keyword.put(options, :depth, (options[:depth] || 0) + 1)
+ object = fix_object(object, options)
+
+ params = %{
+ to: data["to"],
+ object: object,
+ actor: user,
+ context: nil,
+ local: false,
+ published: data["published"],
+ additional: Map.take(data, ["cc", "id"])
+ }
+
+ ActivityPub.listen(params)
+ else
+ _e -> :error
+ end
+ end
+
+ def handle_incoming(
+ %{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data,
+ _options
+ ) do
+ with %User{local: true} = followed <-
+ User.get_cached_by_ap_id(Containment.get_actor(%{"actor" => followed})),
+ {:ok, %User{} = follower} <-
+ User.get_or_fetch_by_ap_id(Containment.get_actor(%{"actor" => follower})),