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
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