Add blocks to User.
This commit is contained in:
parent
345ad870f7
commit
6a5f087174
2 changed files with 47 additions and 0 deletions
|
@ -293,4 +293,28 @@ def search(query, resolve) do
|
|||
limit: 20
|
||||
Repo.all(q)
|
||||
end
|
||||
|
||||
def block(user, %{ap_id: ap_id}) do
|
||||
blocks = user.info["blocks"] || []
|
||||
new_blocks = Enum.uniq([ap_id | blocks])
|
||||
new_info = Map.put(user.info, "blocks", new_blocks)
|
||||
|
||||
cs = User.info_changeset(user, %{info: new_info})
|
||||
Repo.update(cs)
|
||||
end
|
||||
|
||||
def unblock(user, %{ap_id: ap_id}) do
|
||||
blocks = user.info["blocks"] || []
|
||||
new_blocks = List.delete(blocks, ap_id)
|
||||
new_info = Map.put(user.info, "blocks", new_blocks)
|
||||
|
||||
cs = User.info_changeset(user, %{info: new_info})
|
||||
Repo.update(cs)
|
||||
end
|
||||
|
||||
def blocks?(user, %{ap_id: ap_id}) do
|
||||
blocks = user.info["blocks"] || []
|
||||
Enum.member?(blocks, ap_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -273,5 +273,28 @@ test "it sets the info->follower_count property" do
|
|||
assert user.info["follower_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "blocks" do
|
||||
test "it blocks people" do
|
||||
user = insert(:user)
|
||||
blocked_user = insert(:user)
|
||||
|
||||
refute User.blocks?(user, blocked_user)
|
||||
|
||||
{:ok, user} = User.block(user, blocked_user)
|
||||
|
||||
assert User.blocks?(user, blocked_user)
|
||||
end
|
||||
|
||||
test "it unblocks users" do
|
||||
user = insert(:user)
|
||||
blocked_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.block(user, blocked_user)
|
||||
{:ok, user} = User.unblock(user, blocked_user)
|
||||
|
||||
refute User.blocks?(user, blocked_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue