1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-11-18 19:14:03 +00:00

Merge branch '2435-list-multiple-users' into 'develop'

Resolve "Add/Remove several accounts from List don't work"

Closes #2435

See merge request pleroma/pleroma!3260
This commit is contained in:
Haelwenn 2021-01-26 14:34:50 +00:00
commit e1eac4faac
3 changed files with 19 additions and 5 deletions

View file

@ -63,6 +63,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<summary>API Changes</summary>
- Mastodon API: Current user is now included in conversation if it's the only participant.
- Mastodon API: Fixed last_status.account being not filled with account data.
- Mastodon API: Fix not being able to add or remove multiple users at once in lists.
- Mastodon API: Fixed own_votes being not returned with poll data.
</details>

View file

@ -113,11 +113,15 @@ def create(title, %User{} = creator) do
end
end
def follow(%Pleroma.List{following: following} = list, %User{} = followed) do
def follow(%Pleroma.List{id: id}, %User{} = followed) do
list = Repo.get(Pleroma.List, id)
%{following: following} = list
update_follows(list, %{following: Enum.uniq([followed.follower_address | following])})
end
def unfollow(%Pleroma.List{following: following} = list, %User{} = unfollowed) do
def unfollow(%Pleroma.List{id: id}, %User{} = unfollowed) do
list = Repo.get(Pleroma.List, id)
%{following: following} = list
update_follows(list, %{following: List.delete(following, unfollowed.follower_address)})
end

View file

@ -55,30 +55,39 @@ test "listing a user's lists" do
test "adding users to a list" do
%{user: user, conn: conn} = oauth_access(["write:lists"])
other_user = insert(:user)
third_user = insert(:user)
{:ok, list} = Pleroma.List.create("name", user)
assert %{} ==
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|> post("/api/v1/lists/#{list.id}/accounts", %{
"account_ids" => [other_user.id, third_user.id]
})
|> json_response_and_validate_schema(:ok)
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
assert following == [other_user.follower_address]
assert length(following) == 2
assert other_user.follower_address in following
assert third_user.follower_address in following
end
test "removing users from a list, body params" do
%{user: user, conn: conn} = oauth_access(["write:lists"])
other_user = insert(:user)
third_user = insert(:user)
fourth_user = insert(:user)
{:ok, list} = Pleroma.List.create("name", user)
{:ok, list} = Pleroma.List.follow(list, other_user)
{:ok, list} = Pleroma.List.follow(list, third_user)
{:ok, list} = Pleroma.List.follow(list, fourth_user)
assert %{} ==
conn
|> put_req_header("content-type", "application/json")
|> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|> delete("/api/v1/lists/#{list.id}/accounts", %{
"account_ids" => [other_user.id, fourth_user.id]
})
|> json_response_and_validate_schema(:ok)
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)