فهرست منبع

fix(rtc): update patch-remote-attr-map-by-local-av-coll

rcmerci 10 ماه پیش
والد
کامیت
32e4563d17
2فایلهای تغییر یافته به همراه71 افزوده شده و 16 حذف شده
  1. 29 16
      src/main/frontend/worker/rtc/remote_update.cljs
  2. 42 0
      src/test/frontend/worker/rtc/rtc_fns_test.cljs

+ 29 - 16
src/main/frontend/worker/rtc/remote_update.cljs

@@ -236,28 +236,41 @@
      (= :db.cardinality/many (:db/cardinality k-schema))]))
 
 (defn- patch-remote-attr-map-by-local-av-coll
-  [attr-map av-coll]
+  [remote-attr-map local-av-coll]
   (let [a->add->v-set
         (reduce
          (fn [m [a v _t add?]]
            (let [{add-vset true retract-vset false} (get m a {true #{} false #{}})]
              (assoc m a {true ((if add? conj disj) add-vset v)
                          false ((if add? disj conj) retract-vset v)})))
-         {} av-coll)]
-    (into attr-map
-          (keep
-           (fn [[remote-a remote-v]]
-             (when-let [{add-vset true retract-vset false} (get a->add->v-set remote-a)]
-               [remote-a
-                (if (coll? remote-v)
-                  (-> (set remote-v)
-                      (set/union add-vset)
-                      (set/difference retract-vset)
-                      vec)
-                  (cond
-                    (seq add-vset) (first add-vset)
-                    (contains? retract-vset remote-v) nil))])))
-          attr-map)))
+         {} local-av-coll)
+        updated-remote-attr-map1
+        (keep
+         (fn [[remote-a remote-v]]
+           (when-let [{add-vset true retract-vset false} (get a->add->v-set remote-a)]
+             [remote-a
+              (if (coll? remote-v)
+                (-> (set remote-v)
+                    (set/union add-vset)
+                    (set/difference retract-vset)
+                    vec)
+                (cond
+                  (seq add-vset) (first add-vset)
+                  (contains? retract-vset remote-v) nil))]))
+         remote-attr-map)
+        updated-remote-attr-map2
+        (keep
+         (fn [[a add->v-set]]
+           (when-let [ns (namespace a)]
+             (when (and (not (contains? #{"block"} ns))
+                        ;; FIXME: only handle non-block/xxx attrs,
+                        ;; because some :block/xxx attrs are card-one, we only generate card-many values here
+                        (not (contains? remote-attr-map a)))
+               (when-let [v-set (not-empty (get add->v-set true))]
+                 [a (vec v-set)]))))
+         a->add->v-set)]
+    (into remote-attr-map
+          (concat updated-remote-attr-map1 updated-remote-attr-map2))))
 
 (defn- update-remote-data-by-local-unpushed-ops
   "when remote-data request client to move/update/remove/... blocks,

+ 42 - 0
src/test/frontend/worker/rtc/rtc_fns_test.cljs

@@ -112,6 +112,48 @@
                :user.property/ppp
                [#uuid "6752bdee-7963-4a6a-84a4-86cd456b470c"
                 #uuid "6752bdf0-ee32-40af-8abb-3f8d179ba888"]}}
+             r))))
+  (testing "case6: toggle status"
+    (let [[uuid1 uuid2 status-value-uuid] (repeatedly random-uuid)
+          affected-blocks-map
+          {uuid1
+           {:op :update-attrs
+            :self uuid1
+            :parents [uuid2]}}
+          unpushed-ops
+          [[:update
+            536872312
+            {:block-uuid uuid1
+             :av-coll
+             [[:logseq.task/status status-value-uuid 536872312 true]]}]]
+          r (#'r.remote/update-remote-data-by-local-unpushed-ops affected-blocks-map unpushed-ops)]
+      (is (= {uuid1
+              {:op :update-attrs
+               :self uuid1
+               :parents [uuid2]
+               :logseq.task/status [status-value-uuid]}}
+             r))))
+  (testing "case7: toggle status(2)"
+    (let [[uuid1 uuid2 status-value-uuid1 status-value-uuid2] (repeatedly random-uuid)
+          affected-blocks-map
+          {uuid1
+           {:op :update-attrs
+            :self uuid1
+            :parents [uuid2]}}
+          unpushed-ops
+          [[:update
+            536872314
+            {:block-uuid uuid1
+             :av-coll
+             [[:logseq.task/status status-value-uuid1 536872312 true]
+              [:logseq.task/status status-value-uuid1 536872312 false]
+              [:logseq.task/status status-value-uuid2 536872314 true]]}]]
+          r (#'r.remote/update-remote-data-by-local-unpushed-ops affected-blocks-map unpushed-ops)]
+      (is (= {uuid1
+              {:op :update-attrs
+               :self uuid1
+               :parents [uuid2]
+               :logseq.task/status [status-value-uuid2]}}
              r)))))
 
 (deftest apply-remote-move-ops-test