+ def follow(%User{ap_id: follower_id, local: actor_local}, %User{ap_id: followed_id}, local \\ true) do
+ data = %{
+ "type" => "Follow",
+ "actor" => follower_id,
+ "to" => [followed_id],
+ "object" => followed_id,
+ "published" => make_date()
+ }
+
+ with {:ok, activity} <- insert(data, local) do
+ if actor_local do
+ Pleroma.Web.Federator.enqueue(:publish, activity)
+ end
+
+ {:ok, activity}
+ end
+ end
+
+ def unfollow(follower, followed, local \\ true) do
+ with follow_activity when not is_nil(follow_activity) <- fetch_latest_follow(follower, followed) do
+ data = %{
+ "type" => "Undo",
+ "actor" => follower.ap_id,
+ "to" => [followed.ap_id],
+ "object" => follow_activity.data["id"],
+ "published" => make_date()
+ }
+
+ with {:ok, activity} <- insert(data, local) do
+ if follower.local do
+ Pleroma.Web.Federator.enqueue(:publish, activity)
+ end
+
+ {:ok, activity}
+ end
+ end
+ end
+