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