mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 23:26:10 +02:00
✨ Reorganize comments related rpc methods
Mutations becomes deprecated and queries moved to commands. The old queries still maintained with deprecated flag.
This commit is contained in:
parent
8237805cf5
commit
05a86581a5
5 changed files with 243 additions and 112 deletions
|
@ -241,6 +241,7 @@
|
||||||
[cfg]
|
[cfg]
|
||||||
(let [cfg (assoc cfg ::type "command" ::metrics-id :rpc-command-timing)]
|
(let [cfg (assoc cfg ::type "command" ::metrics-id :rpc-command-timing)]
|
||||||
(->> (sv/scan-ns 'app.rpc.commands.binfile
|
(->> (sv/scan-ns 'app.rpc.commands.binfile
|
||||||
|
'app.rpc.commands.comments
|
||||||
'app.rpc.commands.auth
|
'app.rpc.commands.auth
|
||||||
'app.rpc.commands.ldap
|
'app.rpc.commands.ldap
|
||||||
'app.rpc.commands.demo)
|
'app.rpc.commands.demo)
|
||||||
|
|
203
backend/src/app/rpc/commands/comments.clj
Normal file
203
backend/src/app/rpc/commands/comments.clj
Normal file
|
@ -0,0 +1,203 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) UXBOX Labs SL
|
||||||
|
|
||||||
|
(ns app.rpc.commands.comments
|
||||||
|
(:require
|
||||||
|
[app.common.spec :as us]
|
||||||
|
[app.common.pages.changes :as changes]
|
||||||
|
[app.db :as db]
|
||||||
|
[app.http.doc :as doc]
|
||||||
|
[app.rpc.queries.files :as files]
|
||||||
|
[app.rpc.queries.teams :as teams]
|
||||||
|
[app.util.services :as sv]
|
||||||
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
(defn decode-row
|
||||||
|
[{:keys [participants position] :as row}]
|
||||||
|
(cond-> row
|
||||||
|
(db/pgpoint? position) (assoc :position (db/decode-pgpoint position))
|
||||||
|
(db/pgobject? participants) (assoc :participants (db/decode-transit-pgobject participants))))
|
||||||
|
|
||||||
|
;; --- COMMAND: Get Comment Threads
|
||||||
|
|
||||||
|
(declare retrieve-comment-threads)
|
||||||
|
|
||||||
|
(s/def ::team-id ::us/uuid)
|
||||||
|
(s/def ::file-id ::us/uuid)
|
||||||
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
|
||||||
|
(s/def ::get-comment-threads
|
||||||
|
(s/and (s/keys :req-un [::profile-id]
|
||||||
|
:opt-un [::file-id ::share-id ::team-id])
|
||||||
|
#(or (:file-id %) (:team-id %))))
|
||||||
|
|
||||||
|
(sv/defmethod ::get-comment-threads
|
||||||
|
[{:keys [pool] :as cfg} params]
|
||||||
|
(with-open [conn (db/open pool)]
|
||||||
|
(retrieve-comment-threads conn params)))
|
||||||
|
|
||||||
|
(def sql:comment-threads
|
||||||
|
"select distinct on (ct.id)
|
||||||
|
ct.*,
|
||||||
|
f.name as file_name,
|
||||||
|
f.project_id as project_id,
|
||||||
|
first_value(c.content) over w as content,
|
||||||
|
(select count(1)
|
||||||
|
from comment as c
|
||||||
|
where c.thread_id = ct.id) as count_comments,
|
||||||
|
(select count(1)
|
||||||
|
from comment as c
|
||||||
|
where c.thread_id = ct.id
|
||||||
|
and c.created_at >= coalesce(cts.modified_at, ct.created_at)) as count_unread_comments
|
||||||
|
from comment_thread as ct
|
||||||
|
inner join comment as c on (c.thread_id = ct.id)
|
||||||
|
inner join file as f on (f.id = ct.file_id)
|
||||||
|
left join comment_thread_status as cts
|
||||||
|
on (cts.thread_id = ct.id and
|
||||||
|
cts.profile_id = ?)
|
||||||
|
where ct.file_id = ?
|
||||||
|
window w as (partition by c.thread_id order by c.created_at asc)")
|
||||||
|
|
||||||
|
(defn retrieve-comment-threads
|
||||||
|
[conn {:keys [profile-id file-id share-id]}]
|
||||||
|
(files/check-comment-permissions! conn profile-id file-id share-id)
|
||||||
|
(->> (db/exec! conn [sql:comment-threads profile-id file-id])
|
||||||
|
(into [] (map decode-row))))
|
||||||
|
|
||||||
|
;; --- COMMAND: Get Unread Comment Threads
|
||||||
|
|
||||||
|
(declare retrieve-unread-comment-threads)
|
||||||
|
|
||||||
|
(s/def ::team-id ::us/uuid)
|
||||||
|
(s/def ::get-unread-comment-threads
|
||||||
|
(s/keys :req-un [::profile-id ::team-id]))
|
||||||
|
|
||||||
|
(sv/defmethod ::get-unread-comment-threads
|
||||||
|
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}]
|
||||||
|
(with-open [conn (db/open pool)]
|
||||||
|
(teams/check-read-permissions! conn profile-id team-id)
|
||||||
|
(retrieve-unread-comment-threads conn params)))
|
||||||
|
|
||||||
|
(def sql:comment-threads-by-team
|
||||||
|
"select distinct on (ct.id)
|
||||||
|
ct.*,
|
||||||
|
f.name as file_name,
|
||||||
|
f.project_id as project_id,
|
||||||
|
first_value(c.content) over w as content,
|
||||||
|
(select count(1)
|
||||||
|
from comment as c
|
||||||
|
where c.thread_id = ct.id) as count_comments,
|
||||||
|
(select count(1)
|
||||||
|
from comment as c
|
||||||
|
where c.thread_id = ct.id
|
||||||
|
and c.created_at >= coalesce(cts.modified_at, ct.created_at)) as count_unread_comments
|
||||||
|
from comment_thread as ct
|
||||||
|
inner join comment as c on (c.thread_id = ct.id)
|
||||||
|
inner join file as f on (f.id = ct.file_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 = ?)
|
||||||
|
where p.team_id = ?
|
||||||
|
window w as (partition by c.thread_id order by c.created_at asc)")
|
||||||
|
|
||||||
|
(def sql:unread-comment-threads-by-team
|
||||||
|
(str "with threads as (" sql:comment-threads-by-team ")"
|
||||||
|
"select * from threads where count_unread_comments > 0"))
|
||||||
|
|
||||||
|
(defn retrieve-unread-comment-threads
|
||||||
|
[conn {:keys [profile-id team-id]}]
|
||||||
|
(->> (db/exec! conn [sql:unread-comment-threads-by-team profile-id team-id])
|
||||||
|
(into [] (map decode-row))))
|
||||||
|
|
||||||
|
|
||||||
|
;; --- COMMAND: Get Single Comment Thread
|
||||||
|
|
||||||
|
(s/def ::id ::us/uuid)
|
||||||
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
(s/def ::get-comment-thread
|
||||||
|
(s/keys :req-un [::profile-id ::file-id ::id]
|
||||||
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
|
(sv/defmethod ::get-comment-thread
|
||||||
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id id share-id] :as params}]
|
||||||
|
(with-open [conn (db/open pool)]
|
||||||
|
(files/check-comment-permissions! conn profile-id file-id share-id)
|
||||||
|
(let [sql (str "with threads as (" sql:comment-threads ")"
|
||||||
|
"select * from threads where id = ?")]
|
||||||
|
(-> (db/exec-one! conn [sql profile-id file-id id])
|
||||||
|
(decode-row)))))
|
||||||
|
|
||||||
|
;; --- COMMAND: Comments
|
||||||
|
|
||||||
|
(declare retrieve-comments)
|
||||||
|
|
||||||
|
(s/def ::file-id ::us/uuid)
|
||||||
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
(s/def ::thread-id ::us/uuid)
|
||||||
|
(s/def ::get-comments
|
||||||
|
(s/keys :req-un [::profile-id ::thread-id]
|
||||||
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
|
(sv/defmethod ::get-comments
|
||||||
|
[{:keys [pool] :as cfg} {:keys [profile-id thread-id share-id] :as params}]
|
||||||
|
(with-open [conn (db/open pool)]
|
||||||
|
(let [thread (db/get-by-id conn :comment-thread thread-id)]
|
||||||
|
(files/check-comment-permissions! conn profile-id (:file-id thread) share-id)
|
||||||
|
(retrieve-comments conn thread-id))))
|
||||||
|
|
||||||
|
(def sql:comments
|
||||||
|
"select c.* from comment as c
|
||||||
|
where c.thread_id = ?
|
||||||
|
order by c.created_at asc")
|
||||||
|
|
||||||
|
(defn retrieve-comments
|
||||||
|
[conn thread-id]
|
||||||
|
(->> (db/exec! conn [sql:comments thread-id])
|
||||||
|
(into [] (map decode-row))))
|
||||||
|
|
||||||
|
;; --- COMMAND: Get file comments users
|
||||||
|
|
||||||
|
(declare retrieve-file-comments-users)
|
||||||
|
|
||||||
|
(s/def ::file-id ::us/uuid)
|
||||||
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
|
||||||
|
(s/def ::get-profiles-for-file-comments
|
||||||
|
(s/keys :req-un [::profile-id ::file-id]
|
||||||
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
|
(sv/defmethod ::get-profiles-for-file-comments
|
||||||
|
"Retrieves a list of profiles with limited set of properties of all
|
||||||
|
participants on comment threads of the file."
|
||||||
|
{::doc/added "1.15"
|
||||||
|
::doc/changes ["1.15" "Imported from queries and renamed."]}
|
||||||
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id share-id]}]
|
||||||
|
(with-open [conn (db/open pool)]
|
||||||
|
(files/check-comment-permissions! conn profile-id file-id share-id)
|
||||||
|
(retrieve-file-comments-users conn file-id profile-id)))
|
||||||
|
|
||||||
|
;; All the profiles that had comment the file, plus the current
|
||||||
|
;; profile.
|
||||||
|
|
||||||
|
(def sql:file-comment-users
|
||||||
|
"WITH available_profiles AS (
|
||||||
|
SELECT DISTINCT owner_id AS id
|
||||||
|
FROM comment
|
||||||
|
WHERE thread_id IN (SELECT id FROM comment_thread WHERE file_id=?)
|
||||||
|
)
|
||||||
|
SELECT p.id,
|
||||||
|
p.email,
|
||||||
|
p.fullname AS name,
|
||||||
|
p.fullname AS fullname,
|
||||||
|
p.photo_id,
|
||||||
|
p.is_active
|
||||||
|
FROM profile AS p
|
||||||
|
WHERE p.id IN (SELECT id FROM available_profiles) OR p.id=?")
|
||||||
|
|
||||||
|
(defn retrieve-file-comments-users
|
||||||
|
[conn file-id profile-id]
|
||||||
|
(db/exec! conn [sql:file-comment-users file-id profile-id]))
|
|
@ -10,6 +10,7 @@
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.http.doc :as doc]
|
||||||
[app.rpc.queries.comments :as comments]
|
[app.rpc.queries.comments :as comments]
|
||||||
[app.rpc.queries.files :as files]
|
[app.rpc.queries.files :as files]
|
||||||
[app.rpc.retry :as retry]
|
[app.rpc.retry :as retry]
|
||||||
|
@ -37,7 +38,9 @@
|
||||||
|
|
||||||
(sv/defmethod ::create-comment-thread
|
(sv/defmethod ::create-comment-thread
|
||||||
{::retry/max-retries 3
|
{::retry/max-retries 3
|
||||||
::retry/matches retry/conflict-db-insert?}
|
::retry/matches retry/conflict-db-insert?
|
||||||
|
::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id share-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(files/check-comment-permissions! conn profile-id file-id share-id)
|
(files/check-comment-permissions! conn profile-id file-id share-id)
|
||||||
|
@ -101,6 +104,8 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::update-comment-thread-status
|
(sv/defmethod ::update-comment-thread-status
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id id share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id id share-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [cthr (db/get-by-id conn :comment-thread id {:for-update true})]
|
(let [cthr (db/get-by-id conn :comment-thread id {:for-update true})]
|
||||||
|
@ -130,6 +135,8 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::update-comment-thread
|
(sv/defmethod ::update-comment-thread
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id id is-resolved share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id id is-resolved share-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [thread (db/get-by-id conn :comment-thread id {:for-update true})]
|
(let [thread (db/get-by-id conn :comment-thread id {:for-update true})]
|
||||||
|
@ -151,6 +158,8 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::add-comment
|
(sv/defmethod ::add-comment
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id thread-id content share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id thread-id content share-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [thread (-> (db/get-by-id conn :comment-thread thread-id {:for-update true})
|
(let [thread (-> (db/get-by-id conn :comment-thread thread-id {:for-update true})
|
||||||
|
@ -209,6 +218,8 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::update-comment
|
(sv/defmethod ::update-comment
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id id content share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id id content share-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [comment (db/get-by-id conn :comment id {:for-update true})
|
(let [comment (db/get-by-id conn :comment id {:for-update true})
|
||||||
|
@ -242,6 +253,8 @@
|
||||||
(s/keys :req-un [::profile-id ::id]))
|
(s/keys :req-un [::profile-id ::id]))
|
||||||
|
|
||||||
(sv/defmethod ::delete-comment-thread
|
(sv/defmethod ::delete-comment-thread
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [thread (db/get-by-id conn :comment-thread id {:for-update true})]
|
(let [thread (db/get-by-id conn :comment-thread id {:for-update true})]
|
||||||
|
@ -258,6 +271,8 @@
|
||||||
(s/keys :req-un [::profile-id ::id]))
|
(s/keys :req-un [::profile-id ::id]))
|
||||||
|
|
||||||
(sv/defmethod ::delete-comment
|
(sv/defmethod ::delete-comment
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [comment (db/get-by-id conn :comment id {:for-update true})]
|
(let [comment (db/get-by-id conn :comment id {:for-update true})]
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.http.doc :as doc]
|
||||||
|
[app.rpc.commands.comments :as cmd.comments]
|
||||||
[app.rpc.queries.files :as files]
|
[app.rpc.queries.files :as files]
|
||||||
[app.rpc.queries.teams :as teams]
|
[app.rpc.queries.teams :as teams]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
|
@ -19,9 +21,7 @@
|
||||||
(db/pgpoint? position) (assoc :position (db/decode-pgpoint position))
|
(db/pgpoint? position) (assoc :position (db/decode-pgpoint position))
|
||||||
(db/pgobject? participants) (assoc :participants (db/decode-transit-pgobject participants))))
|
(db/pgobject? participants) (assoc :participants (db/decode-transit-pgobject participants))))
|
||||||
|
|
||||||
;; --- Query: Comment Threads
|
;; --- QUERY: Comment Threads
|
||||||
|
|
||||||
(declare retrieve-comment-threads)
|
|
||||||
|
|
||||||
(s/def ::team-id ::us/uuid)
|
(s/def ::team-id ::us/uuid)
|
||||||
(s/def ::file-id ::us/uuid)
|
(s/def ::file-id ::us/uuid)
|
||||||
|
@ -33,87 +33,27 @@
|
||||||
#(or (:file-id %) (:team-id %))))
|
#(or (:file-id %) (:team-id %))))
|
||||||
|
|
||||||
(sv/defmethod ::comment-threads
|
(sv/defmethod ::comment-threads
|
||||||
|
{::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} params]
|
[{:keys [pool] :as cfg} params]
|
||||||
(with-open [conn (db/open pool)]
|
(with-open [conn (db/open pool)]
|
||||||
(retrieve-comment-threads conn params)))
|
(cmd.comments/retrieve-comment-threads conn params)))
|
||||||
|
|
||||||
(def sql:comment-threads
|
|
||||||
"select distinct on (ct.id)
|
|
||||||
ct.*,
|
|
||||||
f.name as file_name,
|
|
||||||
f.project_id as project_id,
|
|
||||||
first_value(c.content) over w as content,
|
|
||||||
(select count(1)
|
|
||||||
from comment as c
|
|
||||||
where c.thread_id = ct.id) as count_comments,
|
|
||||||
(select count(1)
|
|
||||||
from comment as c
|
|
||||||
where c.thread_id = ct.id
|
|
||||||
and c.created_at >= coalesce(cts.modified_at, ct.created_at)) as count_unread_comments
|
|
||||||
from comment_thread as ct
|
|
||||||
inner join comment as c on (c.thread_id = ct.id)
|
|
||||||
inner join file as f on (f.id = ct.file_id)
|
|
||||||
left join comment_thread_status as cts
|
|
||||||
on (cts.thread_id = ct.id and
|
|
||||||
cts.profile_id = ?)
|
|
||||||
where ct.file_id = ?
|
|
||||||
window w as (partition by c.thread_id order by c.created_at asc)")
|
|
||||||
|
|
||||||
(defn- retrieve-comment-threads
|
|
||||||
[conn {:keys [profile-id file-id share-id]}]
|
|
||||||
(files/check-comment-permissions! conn profile-id file-id share-id)
|
|
||||||
(->> (db/exec! conn [sql:comment-threads profile-id file-id])
|
|
||||||
(into [] (map decode-row))))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Query: Unread Comment Threads
|
;; --- QUERY: Unread Comment Threads
|
||||||
|
|
||||||
(declare retrieve-unread-comment-threads)
|
|
||||||
|
|
||||||
(s/def ::team-id ::us/uuid)
|
(s/def ::team-id ::us/uuid)
|
||||||
(s/def ::unread-comment-threads
|
(s/def ::unread-comment-threads
|
||||||
(s/keys :req-un [::profile-id ::team-id]))
|
(s/keys :req-un [::profile-id ::team-id]))
|
||||||
|
|
||||||
(sv/defmethod ::unread-comment-threads
|
(sv/defmethod ::unread-comment-threads
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id team-id] :as params}]
|
||||||
(with-open [conn (db/open pool)]
|
(with-open [conn (db/open pool)]
|
||||||
(teams/check-read-permissions! conn profile-id team-id)
|
(teams/check-read-permissions! conn profile-id team-id)
|
||||||
(retrieve-unread-comment-threads conn params)))
|
(cmd.comments/retrieve-unread-comment-threads conn params)))
|
||||||
|
|
||||||
(def sql:comment-threads-by-team
|
;; --- QUERY: Single Comment Thread
|
||||||
"select distinct on (ct.id)
|
|
||||||
ct.*,
|
|
||||||
f.name as file_name,
|
|
||||||
f.project_id as project_id,
|
|
||||||
first_value(c.content) over w as content,
|
|
||||||
(select count(1)
|
|
||||||
from comment as c
|
|
||||||
where c.thread_id = ct.id) as count_comments,
|
|
||||||
(select count(1)
|
|
||||||
from comment as c
|
|
||||||
where c.thread_id = ct.id
|
|
||||||
and c.created_at >= coalesce(cts.modified_at, ct.created_at)) as count_unread_comments
|
|
||||||
from comment_thread as ct
|
|
||||||
inner join comment as c on (c.thread_id = ct.id)
|
|
||||||
inner join file as f on (f.id = ct.file_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 = ?)
|
|
||||||
where p.team_id = ?
|
|
||||||
window w as (partition by c.thread_id order by c.created_at asc)")
|
|
||||||
|
|
||||||
(def sql:unread-comment-threads-by-team
|
|
||||||
(str "with threads as (" sql:comment-threads-by-team ")"
|
|
||||||
"select * from threads where count_unread_comments > 0"))
|
|
||||||
|
|
||||||
(defn retrieve-unread-comment-threads
|
|
||||||
[conn {:keys [profile-id team-id]}]
|
|
||||||
(->> (db/exec! conn [sql:unread-comment-threads-by-team profile-id team-id])
|
|
||||||
(into [] (map decode-row))))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Query: Single Comment Thread
|
|
||||||
|
|
||||||
(s/def ::id ::us/uuid)
|
(s/def ::id ::us/uuid)
|
||||||
(s/def ::share-id (s/nilable ::us/uuid))
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
@ -122,17 +62,17 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::comment-thread
|
(sv/defmethod ::comment-thread
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id id share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id id share-id] :as params}]
|
||||||
(with-open [conn (db/open pool)]
|
(with-open [conn (db/open pool)]
|
||||||
(files/check-comment-permissions! conn profile-id file-id share-id)
|
(files/check-comment-permissions! conn profile-id file-id share-id)
|
||||||
(let [sql (str "with threads as (" sql:comment-threads ")"
|
(let [sql (str "with threads as (" cmd.comments/sql:comment-threads ")"
|
||||||
"select * from threads where id = ?")]
|
"select * from threads where id = ?")]
|
||||||
(-> (db/exec-one! conn [sql profile-id file-id id])
|
(-> (db/exec-one! conn [sql profile-id file-id id])
|
||||||
(decode-row)))))
|
(decode-row)))))
|
||||||
|
|
||||||
;; --- Query: Comments
|
;; --- QUERY: Comments
|
||||||
|
|
||||||
(declare retrieve-comments)
|
|
||||||
|
|
||||||
(s/def ::file-id ::us/uuid)
|
(s/def ::file-id ::us/uuid)
|
||||||
(s/def ::share-id (s/nilable ::us/uuid))
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
@ -142,25 +82,15 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::comments
|
(sv/defmethod ::comments
|
||||||
|
{::doc/added "1.0"
|
||||||
|
::doc/deprecated "1.15"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id thread-id share-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id thread-id share-id] :as params}]
|
||||||
(with-open [conn (db/open pool)]
|
(with-open [conn (db/open pool)]
|
||||||
(let [thread (db/get-by-id conn :comment-thread thread-id)]
|
(let [thread (db/get-by-id conn :comment-thread thread-id)]
|
||||||
(files/check-comment-permissions! conn profile-id (:file-id thread) share-id)
|
(files/check-comment-permissions! conn profile-id (:file-id thread) share-id)
|
||||||
(retrieve-comments conn thread-id))))
|
(cmd.comments/retrieve-comments conn thread-id))))
|
||||||
|
|
||||||
(def sql:comments
|
;; --- QUERY: Get file comments users
|
||||||
"select c.* from comment as c
|
|
||||||
where c.thread_id = ?
|
|
||||||
order by c.created_at asc")
|
|
||||||
|
|
||||||
(defn- retrieve-comments
|
|
||||||
[conn thread-id]
|
|
||||||
(->> (db/exec! conn [sql:comments thread-id])
|
|
||||||
(into [] (map decode-row))))
|
|
||||||
|
|
||||||
;; file-comments-users
|
|
||||||
|
|
||||||
(declare retrieve-file-comments-users)
|
|
||||||
|
|
||||||
(s/def ::file-id ::us/uuid)
|
(s/def ::file-id ::us/uuid)
|
||||||
(s/def ::share-id (s/nilable ::us/uuid))
|
(s/def ::share-id (s/nilable ::us/uuid))
|
||||||
|
@ -170,27 +100,9 @@
|
||||||
:opt-un [::share-id]))
|
:opt-un [::share-id]))
|
||||||
|
|
||||||
(sv/defmethod ::file-comments-users
|
(sv/defmethod ::file-comments-users
|
||||||
|
{::doc/deprecated "1.15"
|
||||||
|
::doc/added "1.13"}
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id share-id]}]
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id share-id]}]
|
||||||
(with-open [conn (db/open pool)]
|
(with-open [conn (db/open pool)]
|
||||||
(files/check-comment-permissions! conn profile-id file-id share-id)
|
(files/check-comment-permissions! conn profile-id file-id share-id)
|
||||||
(retrieve-file-comments-users conn file-id profile-id)))
|
(cmd.comments/retrieve-file-comments-users conn file-id profile-id)))
|
||||||
|
|
||||||
(def sql:file-comment-users
|
|
||||||
"select p.id,
|
|
||||||
p.email,
|
|
||||||
p.fullname as name,
|
|
||||||
p.fullname as fullname,
|
|
||||||
p.photo_id,
|
|
||||||
p.is_active
|
|
||||||
from profile p
|
|
||||||
where p.id in
|
|
||||||
(select owner_id from comment
|
|
||||||
where thread_id in
|
|
||||||
(select id from comment_thread
|
|
||||||
where file_id=?))
|
|
||||||
or p.id=?
|
|
||||||
") ;; all the users that had comment the file, plus the current user
|
|
||||||
|
|
||||||
(defn retrieve-file-comments-users
|
|
||||||
[conn file-id profile-id]
|
|
||||||
(db/exec! conn [sql:file-comment-users file-id profile-id]))
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.rpc.queries.comments :as comments]
|
[app.rpc.commands.comments :as comments]
|
||||||
[app.rpc.queries.files :as files]
|
[app.rpc.queries.files :as files]
|
||||||
[app.rpc.queries.share-link :as slnk]
|
[app.rpc.queries.share-link :as slnk]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue