forked from YokaiRick/akkoma
Merge branch 'pleroma-list-belongs' into 'develop'
Pleroma list belongs Closes #333 See merge request pleroma/pleroma!382
This commit is contained in:
commit
aaf3fc1575
4 changed files with 46 additions and 0 deletions
|
@ -69,6 +69,25 @@ def get_lists_from_activity(%Activity{actor: ap_id}) do
|
|||
Repo.all(query)
|
||||
end
|
||||
|
||||
# Get lists to which the account belongs.
|
||||
def get_lists_account_belongs(%User{} = owner, account_id) do
|
||||
user = Repo.get(User, account_id)
|
||||
|
||||
query =
|
||||
from(
|
||||
l in Pleroma.List,
|
||||
where:
|
||||
l.user_id == ^owner.id and
|
||||
fragment(
|
||||
"? = ANY(?)",
|
||||
^user.follower_address,
|
||||
l.following
|
||||
)
|
||||
)
|
||||
|
||||
Repo.all(query)
|
||||
end
|
||||
|
||||
def rename(%Pleroma.List{} = list, title) do
|
||||
list
|
||||
|> title_changeset(%{title: title})
|
||||
|
|
|
@ -770,6 +770,12 @@ def get_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|||
end
|
||||
end
|
||||
|
||||
def account_lists(%{assigns: %{user: user}} = conn, %{"id" => account_id}) do
|
||||
lists = Pleroma.List.get_lists_account_belongs(user, account_id)
|
||||
res = ListView.render("lists.json", lists: lists)
|
||||
json(conn, res)
|
||||
end
|
||||
|
||||
def delete_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
|
||||
{:ok, _list} <- Pleroma.List.delete(list) do
|
||||
|
|
|
@ -119,6 +119,7 @@ defmodule Pleroma.Web.Router do
|
|||
post("/accounts/:id/unblock", MastodonAPIController, :unblock)
|
||||
post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
|
||||
post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
|
||||
get("/accounts/:id/lists", MastodonAPIController, :account_lists)
|
||||
|
||||
get("/follow_requests", MastodonAPIController, :follow_requests)
|
||||
post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
|
||||
|
|
|
@ -90,4 +90,24 @@ test "getting all lists the user is a member of" do
|
|||
assert list_two in lists
|
||||
refute list_three in lists
|
||||
end
|
||||
|
||||
test "getting own lists a given user belongs to" do
|
||||
owner = insert(:user)
|
||||
not_owner = insert(:user)
|
||||
member_1 = insert(:user)
|
||||
member_2 = insert(:user)
|
||||
{:ok, owned_list} = Pleroma.List.create("owned", owner)
|
||||
{:ok, not_owned_list} = Pleroma.List.create("not owned", not_owner)
|
||||
{:ok, owned_list} = Pleroma.List.follow(owned_list, member_1)
|
||||
{:ok, owned_list} = Pleroma.List.follow(owned_list, member_2)
|
||||
{:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_1)
|
||||
{:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_2)
|
||||
|
||||
lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id)
|
||||
assert owned_list in lists_1
|
||||
refute not_owned_list in lists_1
|
||||
lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id)
|
||||
assert owned_list in lists_2
|
||||
refute not_owned_list in lists_2
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue