Merge pull request #6613 from logseq/fix/delete-remote-graph

fix: deleted remote graph
pull/6581/merge
rcmerci 2022-09-06 15:15:38 +08:00 committed by GitHub
commit ccce48a7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 22 deletions

View File

@ -1,5 +1,7 @@
(ns frontend.components.file-sync
(:require [cljs.core.async :as async]
[cljs.core.async.interop :refer [p->c]]
[frontend.util.persist-var :as persist-var]
[clojure.string :as string]
[electron.ipc :as ipc]
[frontend.components.lazy-editor :as lazy-editor]
@ -197,6 +199,7 @@
(state/set-modal! confirm-fn {:center? true :close-btn? false})))
turn-on #(async/go
(async/<! (p->c (persist-var/-load fs-sync/graphs-txid)))
(cond
@*beta-unavailable?
(state/pub-event! [:file-sync/onboarding-tip :unavailable])

View File

@ -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)))
(<! (p->c (persist-var/-load graphs-txid)))
(.start sm)
(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)
(offer! remote->local-full-sync-chan true)
(offer! full-sync-chan true)))))))))
;; 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