mirror of
https://github.com/penpot/penpot.git
synced 2026-07-27 08:28:17 +00:00
🐛 Fix incorrect filtering of unread comment threads
Do not return threads for deleted files
This commit is contained in:
parent
72b44240b1
commit
d07e00da21
@ -257,6 +257,8 @@
|
|||||||
INNER JOIN project AS p ON (p.id = f.project_id)
|
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 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)
|
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)")
|
WINDOW w AS (PARTITION BY c.thread_id ORDER BY c.created_at ASC)")
|
||||||
|
|
||||||
(def ^:private sql:comment-threads-by-file-id
|
(def ^:private sql:comment-threads-by-file-id
|
||||||
@ -270,7 +272,35 @@
|
|||||||
|
|
||||||
;; --- COMMAND: Get Unread Comment Threads
|
;; --- 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
|
(def ^:private
|
||||||
schema:get-unread-comment-threads
|
schema:get-unread-comment-threads
|
||||||
@ -281,41 +311,8 @@
|
|||||||
{::doc/added "1.15"
|
{::doc/added "1.15"
|
||||||
::sm/params schema:get-unread-comment-threads}
|
::sm/params schema:get-unread-comment-threads}
|
||||||
[cfg {:keys [::rpc/profile-id team-id] :as params}]
|
[cfg {:keys [::rpc/profile-id team-id] :as params}]
|
||||||
(db/run!
|
(teams/check-read-permissions! cfg profile-id team-id)
|
||||||
cfg
|
(get-unread-comment-threads cfg profile-id team-id))
|
||||||
(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))
|
|
||||||
|
|
||||||
[])))
|
|
||||||
|
|
||||||
;; --- COMMAND: Get Single Comment Thread
|
;; --- COMMAND: Get Single Comment Thread
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user