mirror of
https://github.com/penpot/penpot.git
synced 2025-03-18 10:41:29 -05:00
🐛 Add version to presence and fixes off-page updates
This commit is contained in:
parent
cbe8587db3
commit
a118f34b49
2 changed files with 18 additions and 8 deletions
|
@ -204,7 +204,7 @@
|
|||
(a/<! (mbus/sub! msgbus :topic team-id :chan channel)))))
|
||||
|
||||
(defmethod handle-message :subscribe-file
|
||||
[cfg wsp {:keys [file-id] :as params}]
|
||||
[cfg wsp {:keys [file-id version] :as params}]
|
||||
(let [msgbus (::mbus/msgbus cfg)
|
||||
conn-id (::ws/id @wsp)
|
||||
profile-id (::profile-id @wsp)
|
||||
|
@ -239,7 +239,8 @@
|
|||
(let [message {:type :presence
|
||||
:file-id file-id
|
||||
:session-id session-id
|
||||
:profile-id profile-id}]
|
||||
:profile-id profile-id
|
||||
:version version}]
|
||||
(a/<! (mbus/pub! msgbus :topic file-id :message message))))
|
||||
(a/>! output-ch message)
|
||||
(recur))))
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.persistence :as dwp]
|
||||
[app.main.streams :as ms]
|
||||
[app.util.globals :refer [global]]
|
||||
[app.util.object :as obj]
|
||||
[app.util.time :as dt]
|
||||
[beicon.core :as rx]
|
||||
[cljs.spec.alpha :as s]
|
||||
|
@ -37,7 +39,8 @@
|
|||
profile-id (:profile-id state)
|
||||
|
||||
initmsg [{:type :subscribe-file
|
||||
:file-id file-id}
|
||||
:file-id file-id
|
||||
:version (obj/get global "penpotVersion")}
|
||||
{:type :subscribe-team
|
||||
:team-id team-id}]
|
||||
|
||||
|
@ -130,7 +133,7 @@
|
|||
})
|
||||
|
||||
(defn handle-presence
|
||||
[{:keys [type session-id profile-id] :as message}]
|
||||
[{:keys [type session-id profile-id version] :as message}]
|
||||
(letfn [(get-next-color [presence]
|
||||
(let [xfm (comp (map second)
|
||||
(map :color)
|
||||
|
@ -149,6 +152,7 @@
|
|||
(assoc :id session-id)
|
||||
(assoc :profile-id profile-id)
|
||||
(assoc :updated-at (dt/now))
|
||||
(assoc :version version)
|
||||
(update :color update-color presence)
|
||||
(assoc :text-color (if (contains? ["#00fa9a" "#ffd700" "#dda0dd" "#ffafda"]
|
||||
(update-color (:color presence) presence))
|
||||
|
@ -197,8 +201,9 @@
|
|||
(-deref [_] {:changes changes})
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(let [position-data-operation?
|
||||
(watch [_ state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
position-data-operation?
|
||||
(fn [{:keys [type attr]}]
|
||||
(and (= :set type) (= attr :position-data)))
|
||||
|
||||
|
@ -213,7 +218,8 @@
|
|||
;; Remove the position data from remote operations. Will be changed localy, otherwise
|
||||
;; creates a strange "out-of-sync" behaviour.
|
||||
(cond-> change
|
||||
(= :mod-obj (:type change))
|
||||
(and (= page-id (:page-id change))
|
||||
(= :mod-obj (:type change)))
|
||||
(update :operations #(d/removev position-data-operation? %))))
|
||||
|
||||
process-page-changes
|
||||
|
@ -223,7 +229,10 @@
|
|||
;; We update `position-data` from the incoming message
|
||||
changes (->> changes
|
||||
(mapv update-position-data)
|
||||
(d/removev :ignore-remote?))
|
||||
(d/removev (fn [change]
|
||||
(and (= page-id (:page-id change))
|
||||
(:ignore-remote? change)))))
|
||||
|
||||
changes-by-pages (group-by :page-id changes)]
|
||||
|
||||
(rx/merge
|
||||
|
|
Loading…
Add table
Reference in a new issue