[#1335] Applied code review suggestions.
This commit is contained in:
parent
3db988250b
commit
5cf2c7422b
|
@ -1090,11 +1090,10 @@ def blocked_users(user) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def blocked_ap_ids(user) do
|
def blocked_ap_ids(user) do
|
||||||
Repo.all(
|
user
|
||||||
from(u in assoc(user, :blocked_users),
|
|> assoc(:blocked_users)
|
||||||
select: u.ap_id
|
|> select([u], u.ap_id)
|
||||||
)
|
|> Repo.all()
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec subscribers(User.t()) :: [User.t()]
|
@spec subscribers(User.t()) :: [User.t()]
|
||||||
|
|
|
@ -99,17 +99,12 @@ defp base_query(_user, false), do: User
|
||||||
defp base_query(user, true), do: User.get_followers_query(user)
|
defp base_query(user, true), do: User.get_followers_query(user)
|
||||||
|
|
||||||
defp filter_blocked_user(query, %User{} = blocker) do
|
defp filter_blocked_user(query, %User{} = blocker) do
|
||||||
blocker_id = FlakeId.from_string(blocker.id)
|
query
|
||||||
|
|> join(:left, [u], b in Pleroma.UserBlock,
|
||||||
from(
|
as: :blocks,
|
||||||
q in query,
|
on: b.blocker_id == ^blocker.id and u.id == b.blockee_id
|
||||||
where:
|
|
||||||
fragment(
|
|
||||||
"? NOT IN (SELECT blockee_id FROM user_blocks WHERE user_blocks.blocker_id = ?)",
|
|
||||||
q.id,
|
|
||||||
^blocker_id
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|> where([blocks: b], is_nil(b.blockee_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp filter_blocked_user(query, _), do: query
|
defp filter_blocked_user(query, _), do: query
|
||||||
|
|
|
@ -45,24 +45,23 @@ def create(%User{} = blocker, %User{} = blockee) do
|
||||||
def delete(%User{} = blocker, %User{} = blockee) do
|
def delete(%User{} = blocker, %User{} = blockee) do
|
||||||
attrs = %{blocker_id: blocker.id, blockee_id: blockee.id}
|
attrs = %{blocker_id: blocker.id, blockee_id: blockee.id}
|
||||||
|
|
||||||
if is_nil(existing_record = Repo.get_by(UserBlock, attrs)) do
|
case Repo.get_by(UserBlock, attrs) do
|
||||||
{:ok, nil}
|
%UserBlock{} = existing_record -> Repo.delete(existing_record)
|
||||||
else
|
nil -> {:ok, nil}
|
||||||
Repo.delete(existing_record)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp validate_not_self_block(%Ecto.Changeset{} = changeset) do
|
defp validate_not_self_block(%Ecto.Changeset{} = changeset) do
|
||||||
changeset
|
changeset
|
||||||
|> validate_change(:blockee_id, fn _, blockee_id ->
|
|> validate_change(:blockee_id, fn _, blockee_id ->
|
||||||
if blockee_id == changeset.changes[:blocker_id] || changeset.data.blocker_id do
|
if blockee_id == get_field(changeset, :blocker_id) do
|
||||||
[blockee_id: "can't be equal to blocker_id"]
|
[blockee_id: "can't be equal to blocker_id"]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|> validate_change(:blocker_id, fn _, blocker_id ->
|
|> validate_change(:blocker_id, fn _, blocker_id ->
|
||||||
if blocker_id == changeset.changes[:blockee_id] || changeset.data.blockee_id do
|
if blocker_id == get_field(changeset, :blockee_id) do
|
||||||
[blocker_id: "can't be equal to blockee_id"]
|
[blocker_id: "can't be equal to blockee_id"]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Reference in New Issue