end
end
- def upload(%Plug.Upload{} = file) do
+ def unfollow(%User{} = follower, %{ "screen_name" => followed_name }) do
+ with %User{} = followed <- Repo.get_by(User, nickname: followed_name),
+ { :ok, follower } <- User.unfollow(follower, followed)
+ do
+ { :ok, follower, followed }
+ end
+ end
+
+ def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do
+ object = Object.get_by_ap_id(object["id"])
+
+ {:ok, _like_activity, object} = ActivityPub.like(user, object)
+ new_data = activity.data
+ |> Map.put("object", object.data)
+
+ status = %{activity | data: new_data}
+ |> activity_to_status(%{for: user})
+
+ {:ok, status}
+ end
+
+ def unfavorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) do
+ object = Object.get_by_ap_id(object["id"])
+
+ {:ok, object} = ActivityPub.unlike(user, object)
+ new_data = activity.data
+ |> Map.put("object", object.data)
+
+ status = %{activity | data: new_data}
+ |> activity_to_status(%{for: user})
+
+ {:ok, status}
+ end
+
+ def retweet(%User{} = user, %Activity{data: %{"object" => object}} = activity) do
+ object = Object.get_by_ap_id(object["id"])
+
+ {:ok, _announce_activity, object} = ActivityPub.announce(user, object)
+ new_data = activity.data
+ |> Map.put("object", object.data)
+
+ status = %{activity | data: new_data}
+ |> activity_to_status(%{for: user})
+
+ {:ok, status}
+ end
+
+ def upload(%Plug.Upload{} = file, format \\ "xml") do
{:ok, object} = ActivityPub.upload(file)
url = List.first(object.data["url"])