| 
					
				 | 
			
			
				@@ -173,6 +173,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (def ws-addr config/WS-URL) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+;; Warning: make sure to `persist-var/-load` graphs-txid before using it. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (def graphs-txid (persist-var/persist-var nil "graphs-txid")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (declare assert-local-txid<=remote-txid) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -2732,36 +2733,39 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       result))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 (defn sync-start [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  (let [[user-uuid graph-uuid txid] @graphs-txid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        *sync-state                 (atom (sync-state)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  (let [*sync-state                 (atom (sync-state)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         current-user-uuid           (user/user-uuid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         repo                        (state/get-current-repo)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     (go 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       ;; stop previous sync 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       (<! (<sync-stop)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      (when (and user-uuid graph-uuid txid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 (user/logged-in?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 repo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                 (not (config/demo-graph? repo))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        (when-some [sm (sync-manager-singleton current-user-uuid graph-uuid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                               (config/get-repo-dir repo) repo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                               txid *sync-state)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          (when (check-graph-belong-to-current-user current-user-uuid user-uuid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            (if-not (<! (<check-remote-graph-exists graph-uuid)) ; remote graph has been deleted 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              (clear-graphs-txid! repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              (do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (state/set-file-sync-state repo @*sync-state) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (state/set-file-sync-manager sm) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ;; update global state when *sync-state changes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (add-watch *sync-state ::update-global-state 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                           (fn [_ _ _ n] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                             (state/set-file-sync-state repo n))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (.start sm) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (offer! remote->local-full-sync-chan true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (offer! full-sync-chan true))))))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (<! (p->c (persist-var/-load graphs-txid))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      (let [[user-uuid graph-uuid txid] @graphs-txid] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (when (and user-uuid graph-uuid txid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   (user/logged-in?) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   repo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   (not (config/demo-graph? repo))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          (when-some [sm (sync-manager-singleton current-user-uuid graph-uuid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                 (config/get-repo-dir repo) repo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                 txid *sync-state)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            (when (check-graph-belong-to-current-user current-user-uuid user-uuid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              (if-not (<! (<check-remote-graph-exists graph-uuid)) ; remote graph has been deleted 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (clear-graphs-txid! repo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  (state/set-file-sync-state repo @*sync-state) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  (state/set-file-sync-manager sm) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  ;; update global state when *sync-state changes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  (add-watch *sync-state ::update-global-state 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                             (fn [_ _ _ n] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                               (state/set-file-sync-state repo n))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  (.start sm) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  (offer! remote->local-full-sync-chan true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                  (offer! full-sync-chan true)))))))))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 ;;; ### some add-watches 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |