forked from YokaiRick/akkoma
user.ex: add domain blocks.
This commit is contained in:
parent
9d054d30bc
commit
87566b6e2f
2 changed files with 44 additions and 1 deletions
|
@ -479,7 +479,29 @@ def unblock(user, %{ap_id: ap_id}) do
|
|||
|
||||
def blocks?(user, %{ap_id: ap_id}) do
|
||||
blocks = user.info["blocks"] || []
|
||||
Enum.member?(blocks, ap_id)
|
||||
domain_blocks = user.info["domain_blocks"] || []
|
||||
%{host: host} = URI.parse(ap_id)
|
||||
Enum.member?(blocks, ap_id) || Enum.any?(domain_blocks, fn domain ->
|
||||
host == domain
|
||||
end)
|
||||
end
|
||||
|
||||
def block_domain(user, domain) do
|
||||
domain_blocks = user.info["domain_blocks"] || []
|
||||
new_blocks = Enum.uniq([domain | domain_blocks])
|
||||
new_info = Map.put(user.info, "domain_blocks", new_blocks)
|
||||
|
||||
cs = User.info_changeset(user, %{info: new_info})
|
||||
update_and_set_cache(cs)
|
||||
end
|
||||
|
||||
def unblock_domain(user, domain) do
|
||||
blocks = user.info["domain_blocks"] || []
|
||||
new_blocks = List.delete(blocks, domain)
|
||||
new_info = Map.put(user.info, "domain_blocks", new_blocks)
|
||||
|
||||
cs = User.info_changeset(user, %{info: new_info})
|
||||
update_and_set_cache(cs)
|
||||
end
|
||||
|
||||
def local_user_query() do
|
||||
|
|
|
@ -361,6 +361,27 @@ test "it unblocks users" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "domain blocking" do
|
||||
test "blocks domains" do
|
||||
user = insert(:user)
|
||||
collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
|
||||
|
||||
{:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
|
||||
|
||||
assert User.blocks?(user, collateral_user)
|
||||
end
|
||||
|
||||
test "unblocks domains" do
|
||||
user = insert(:user)
|
||||
collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
|
||||
|
||||
{:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
|
||||
{:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
|
||||
|
||||
refute User.blocks?(user, collateral_user)
|
||||
end
|
||||
end
|
||||
|
||||
test "get recipients from activity" do
|
||||
actor = insert(:user)
|
||||
user = insert(:user, local: true)
|
||||
|
|
Loading…
Reference in a new issue