mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-25 04:53:06 +00:00
Add unfollowing using screen_name parameter
This commit is contained in:
parent
b5e94bf930
commit
c0e5b3459f
|
@ -115,7 +115,7 @@ def follow(%User{} = follower, followed_id) do
|
|||
end
|
||||
end
|
||||
|
||||
def unfollow(%User{} = follower, followed_id) do
|
||||
def unfollow(%User{} = follower, %{ "user_id" => followed_id }) do
|
||||
with %User{} = followed <- Repo.get(User, followed_id),
|
||||
{ :ok, follower } <- User.unfollow(follower, followed)
|
||||
do
|
||||
|
@ -123,6 +123,14 @@ def unfollow(%User{} = follower, followed_id) do
|
|||
end
|
||||
end
|
||||
|
||||
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 upload(%Plug.Upload{} = file) do
|
||||
{:ok, object} = ActivityPub.upload(file)
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@ def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
|||
|> json_reply(200, response)
|
||||
end
|
||||
|
||||
def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
|
||||
{ :ok, user, follower } = TwitterAPI.unfollow(user, followed_id)
|
||||
def unfollow(%{assigns: %{user: user}} = conn, params) do
|
||||
{ :ok, user, follower } = TwitterAPI.unfollow(user, params)
|
||||
|
||||
response = follower |> UserRepresenter.to_json(%{for: user})
|
||||
|
||||
|
|
|
@ -116,11 +116,22 @@ test "Follow another user" do
|
|||
assert follow == activity
|
||||
end
|
||||
|
||||
test "Unfollow another user" do
|
||||
test "Unfollow another user using user_id" do
|
||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
|
||||
|
||||
{:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
|
||||
{:ok, user, _following } = TwitterAPI.unfollow(user, %{"user_id" => following.id})
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
|
||||
assert user.following == []
|
||||
end
|
||||
|
||||
test "Unfollow another user using screen_name" do
|
||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
|
||||
|
||||
{:ok, user, _following } = TwitterAPI.unfollow(user, %{"screen_name" => following.nickname})
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue