From d07e00da217f2dc819f3b8a5ad328dc4b2f7d00a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 13 Oct 2025 14:27:32 +0200 Subject: [PATCH] :bug: Fix incorrect filtering of unread comment threads Do not return threads for deleted files --- backend/src/app/rpc/commands/comments.clj | 69 +++++++++++------------ 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/backend/src/app/rpc/commands/comments.clj b/backend/src/app/rpc/commands/comments.clj index 6627157115..19d4633bf3 100644 --- a/backend/src/app/rpc/commands/comments.clj +++ b/backend/src/app/rpc/commands/comments.clj @@ -257,6 +257,8 @@ INNER JOIN project AS p ON (p.id = f.project_id) LEFT JOIN comment_thread_status AS cts ON (cts.thread_id = ct.id AND cts.profile_id = ?) LEFT JOIN profile AS pf ON (ct.owner_id = pf.id) + WHERE f.deleted_at IS NULL + AND p.deleted_at IS NULL WINDOW w AS (PARTITION BY c.thread_id ORDER BY c.created_at ASC)") (def ^:private sql:comment-threads-by-file-id @@ -270,7 +272,35 @@ ;; --- COMMAND: Get Unread Comment Threads -(declare ^:private get-unread-comment-threads) +(def ^:private sql:unread-all-comment-threads-by-team + (str "WITH threads AS (" sql:comment-threads ")" + "SELECT * FROM threads WHERE count_unread_comments > 0 AND team_id = ?")) + +;; The partial configuration will retrieve only comments created by the user and +;; threads that have a mention to the user. +(def ^:private sql:unread-partial-comment-threads-by-team + (str "WITH threads AS (" sql:comment-threads ")" + "SELECT * FROM threads + WHERE count_unread_comments > 0 + AND team_id = ? + AND (owner_id = ? OR ? = ANY(mentions))")) + +(defn- get-unread-comment-threads + [cfg profile-id team-id] + (let [profile (-> (db/get cfg :profile {:id profile-id}) + (profile/decode-row)) + notify (or (-> profile :props :notifications :dashboard-comments) :all)] + + (case notify + :all + (->> (db/exec! cfg [sql:unread-all-comment-threads-by-team profile-id team-id]) + (into [] xf-decode-row)) + + :partial + (->> (db/exec! cfg [sql:unread-partial-comment-threads-by-team profile-id team-id profile-id profile-id]) + (into [] xf-decode-row)) + + []))) (def ^:private schema:get-unread-comment-threads @@ -281,41 +311,8 @@ {::doc/added "1.15" ::sm/params schema:get-unread-comment-threads} [cfg {:keys [::rpc/profile-id team-id] :as params}] - (db/run! - cfg - (fn [{:keys [::db/conn]}] - (teams/check-read-permissions! conn profile-id team-id) - (get-unread-comment-threads conn profile-id team-id)))) - -(def sql:unread-all-comment-threads-by-team - (str "WITH threads AS (" sql:comment-threads ")" - "SELECT * FROM threads WHERE count_unread_comments > 0 AND team_id = ?")) - -;; The partial configuration will retrieve only comments created by the user and -;; threads that have a mention to the user. -(def sql:unread-partial-comment-threads-by-team - (str "WITH threads AS (" sql:comment-threads ")" - "SELECT * FROM threads - WHERE count_unread_comments > 0 - AND team_id = ? - AND (owner_id = ? OR ? = ANY(mentions))")) - -(defn- get-unread-comment-threads - [conn profile-id team-id] - (let [profile (-> (db/get conn :profile {:id profile-id}) - (profile/decode-row)) - notify (or (-> profile :props :notifications :dashboard-comments) :all)] - - (case notify - :all - (->> (db/exec! conn [sql:unread-all-comment-threads-by-team profile-id team-id]) - (into [] xf-decode-row)) - - :partial - (->> (db/exec! conn [sql:unread-partial-comment-threads-by-team profile-id team-id profile-id profile-id]) - (into [] xf-decode-row)) - - []))) + (teams/check-read-permissions! cfg profile-id team-id) + (get-unread-comment-threads cfg profile-id team-id)) ;; --- COMMAND: Get Single Comment Thread