From a118f34b4943e6de7645d916b2481ee786c4af0a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 16 Mar 2023 16:44:11 +0100 Subject: [PATCH] :bug: Add version to presence and fixes off-page updates --- backend/src/app/http/websocket.clj | 5 +++-- .../main/data/workspace/notifications.cljs | 21 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/src/app/http/websocket.clj b/backend/src/app/http/websocket.clj index f06fd1d7c..1db238d2e 100644 --- a/backend/src/app/http/websocket.clj +++ b/backend/src/app/http/websocket.clj @@ -204,7 +204,7 @@ (a/! output-ch message) (recur)))) diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index 7002f8ea1..3a70a1b88 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -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