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