🎉 Notify shared files clients for update

This commit is contained in:
Andrés Moya 2020-09-17 15:34:31 +02:00 committed by Andrey Antukh
parent 494cd1e96c
commit 3b516aa139
6 changed files with 80 additions and 31 deletions

View file

@ -188,10 +188,6 @@
:library-file-id library-id}))
;; A generic, Changes based (granular) file update method.
(s/def ::changes
@ -202,6 +198,13 @@
(s/def ::update-file
(s/keys :req-un [::id ::session-id ::profile-id ::revn ::changes]))
;; File changes that affect to the library, and must be notified
;; to all clients using it.
(def library-changes
#{:add-color :mod-color :del-color
:add-media :mod-media :del-media
:add-component :mod-component :del-component})
(declare update-file)
(declare retrieve-lagged-changes)
(declare insert-change)
@ -239,11 +242,27 @@
:file-id (:id file)
:session-id sid
:revn (:revn file)
:changes changes}]
:changes changes}
library-changes (filter #(library-changes (:type %)) changes)]
@(redis/run! :publish {:channel (str (:id file))
:message (t/encode-str msg)})
(if (and (:is-shared file) (seq library-changes))
(let [{:keys [team-id] :as project}
(db/get-by-id conn :project (:project-id file))
msg {:type :library-change
:profile-id (:profile-id params)
:file-id (:id file)
:session-id sid
:revn (:revn file)
:changes library-changes}]
@(redis/run! :publish {:channel (str team-id)
:message (t/encode-str msg)})))
(db/update! conn :file
{:revn (:revn file)
:data (:data file)}