From fc2ab285c79df273a3159ade42551b750543564e Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Jul 2024 14:38:20 -0400 Subject: [PATCH] Use compile with opts for comment queries --- lib/philomena/comments/query.ex | 3 ++- .../controllers/api/json/search/comment_controller.ex | 2 +- lib/philomena_web/controllers/comment_controller.ex | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/philomena/comments/query.ex b/lib/philomena/comments/query.ex index 9e9c8986..de2fee03 100644 --- a/lib/philomena/comments/query.ex +++ b/lib/philomena/comments/query.ex @@ -92,7 +92,8 @@ defmodule Philomena.Comments.Query do |> Parser.parse(query_string, context) end - def compile(user, query_string) do + def compile(query_string, opts \\ []) do + user = Keyword.get(opts, :user) query_string = query_string || "" case user do diff --git a/lib/philomena_web/controllers/api/json/search/comment_controller.ex b/lib/philomena_web/controllers/api/json/search/comment_controller.ex index 5dbe5e4c..6942a4ff 100644 --- a/lib/philomena_web/controllers/api/json/search/comment_controller.ex +++ b/lib/philomena_web/controllers/api/json/search/comment_controller.ex @@ -10,7 +10,7 @@ defmodule PhilomenaWeb.Api.Json.Search.CommentController do user = conn.assigns.current_user filter = conn.assigns.current_filter - case Query.compile(user, params["q"] || "") do + case Query.compile(params["q"], user: user) do {:ok, query} -> comments = Comment diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 99b14f25..d64f3e16 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -13,8 +13,8 @@ defmodule PhilomenaWeb.CommentController do conn = Map.put(conn, :params, params) user = conn.assigns.current_user - user - |> Query.compile(cq) + cq + |> Query.compile(user: user) |> render_index(conn, user) end