 
     :ok
   end
+
+  defp get_current_board(board_id, socket) do
+    current_user = socket.assigns.current_user
+
+    cards_query = from c in Card, order_by: c.position
+    lists_query = from l in List, order_by: l.position, preload: [cards: ^cards_query]
+
+    Board.for_user(current_user.id)
+      |> Repo.get(board_id)
+      |> Repo.preload([:user, :invited_users, lists: lists_query])
+  end
 end

    {:noreply, socket}
  end

  def terminate(_reason, socket) do
    board_id = to_string(socket.assigns.board.id)
    user_id = socket.assigns.current_user.id


  def join("boards:" <> board_id, _params, socket) do
    current_user = socket.assigns.current_user
    board = get_current_board(board_id, socket)

    send(self, {:after_join, Monitor.user_joined(board_id, current_user)[board_id]})

