forked from AkkomaGang/akkoma
[#1335] Applied code review suggestions.
This commit is contained in:
parent
3db988250b
commit
5cf2c7422b
3 changed files with 14 additions and 21 deletions
|
@ -1090,11 +1090,10 @@ def blocked_users(user) do
|
|||
end
|
||||
|
||||
def blocked_ap_ids(user) do
|
||||
Repo.all(
|
||||
from(u in assoc(user, :blocked_users),
|
||||
select: u.ap_id
|
||||
)
|
||||
)
|
||||
user
|
||||
|> assoc(:blocked_users)
|
||||
|> select([u], u.ap_id)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@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 filter_blocked_user(query, %User{} = blocker) do
|
||||
blocker_id = FlakeId.from_string(blocker.id)
|
||||
|
||||
from(
|
||||
q in query,
|
||||
where:
|
||||
fragment(
|
||||
"? NOT IN (SELECT blockee_id FROM user_blocks WHERE user_blocks.blocker_id = ?)",
|
||||
q.id,
|
||||
^blocker_id
|
||||
)
|
||||
query
|
||||
|> join(:left, [u], b in Pleroma.UserBlock,
|
||||
as: :blocks,
|
||||
on: b.blocker_id == ^blocker.id and u.id == b.blockee_id
|
||||
)
|
||||
|> where([blocks: b], is_nil(b.blockee_id))
|
||||
end
|
||||
|
||||
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
|
||||
attrs = %{blocker_id: blocker.id, blockee_id: blockee.id}
|
||||
|
||||
if is_nil(existing_record = Repo.get_by(UserBlock, attrs)) do
|
||||
{:ok, nil}
|
||||
else
|
||||
Repo.delete(existing_record)
|
||||
case Repo.get_by(UserBlock, attrs) do
|
||||
%UserBlock{} = existing_record -> Repo.delete(existing_record)
|
||||
nil -> {:ok, nil}
|
||||
end
|
||||
end
|
||||
|
||||
defp validate_not_self_block(%Ecto.Changeset{} = changeset) do
|
||||
changeset
|
||||
|> 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"]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end)
|
||||
|> 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"]
|
||||
else
|
||||
[]
|
||||
|
|
Loading…
Reference in a new issue