Răsfoiți Sursa

fix: wrong prompts when the file is only edited by logseq

Tienson Qin 4 ani în urmă
părinte
comite
0bd53815e9

+ 1 - 4
src/main/frontend/db/model.cljs

@@ -1200,10 +1200,7 @@
   [repo path content]
   (when (and repo path)
     (let [tx-data {:file/path path
-                   :file/content content}
-          tx-data (if (config/local-db? repo)
-                    (dissoc tx-data :file/last-modified-at)
-                    tx-data)]
+                   :file/content content}]
       (react/transact-react!
        repo
        [tx-data]

+ 12 - 11
src/main/frontend/fs.cljs

@@ -62,17 +62,18 @@
 
 (defn write-file!
   [repo dir path content opts]
-  (->
-   (do
-     (protocol/write-file! (get-fs dir) repo dir path content opts)
-     (db/set-file-last-modified-at! repo (config/get-file-path repo path) (js/Date.)))
-   (p/catch (fn [error]
-              (log/error :file/write-failed? {:dir dir
-                                              :path path
-                                              :error error})
-              ;; Disable this temporarily
-              ;; (js/alert "Current file can't be saved! Please copy its content to your local file system and click the refresh button.")
-))))
+  (let [fs-record (get-fs dir)]
+    (->
+    (p/let [_ (protocol/write-file! fs-record repo dir path content opts)]
+      (when-not (= fs-record nfs-record)
+        (db/set-file-last-modified-at! repo (config/get-file-path repo path) (js/Date.))))
+    (p/catch (fn [error]
+               (log/error :file/write-failed? {:dir dir
+                                               :path path
+                                               :error error})
+               ;; Disable this temporarily
+               ;; (js/alert "Current file can't be saved! Please copy its content to your local file system and click the refresh button.")
+               )))))
 
 (defn rename!
   [repo old-path new-path]

+ 4 - 1
src/main/frontend/fs/nfs.cljs

@@ -104,7 +104,8 @@
         (and local-file (.text local-file)))))
 
   (write-file! [this repo dir path content opts]
-    (let [{:keys [old-content last-modified-at]} opts
+    (let [{:keys [old-content]} opts
+          last-modified-at (db/get-file-last-modified-at repo path)
           parts (string/split path "/")
           basename (last parts)
           sub-dir (->> (butlast parts)
@@ -136,7 +137,9 @@
                                        ;; temporally fix
                                        (and path (string/ends-with? path ".excalidraw"))) new?
                      (or
+                      ;; Writing not finished
                       (> pending-writes 0)
+                      ;; not changed by other editors
                       not-changed?
                       new-created?))
               (do

+ 2 - 4
src/main/frontend/handler/file.cljs

@@ -180,8 +180,7 @@
         (reset-file! repo path content))
       (db/set-file-content! repo path content))
     (util/p-handle
-     (fs/write-file! repo (config/get-repo-dir repo) path content {:old-content original-content
-                                                                   :last-modified-at (db/get-file-last-modified-at repo path)})
+     (fs/write-file! repo (config/get-repo-dir repo) path content {:old-content original-content})
      (fn [_]
        (git-handler/git-add repo path update-status?)
        (when (= path (config/get-config-path repo))
@@ -240,8 +239,7 @@
                        (let [original-content (get file->content path)]
                          (-> (p/let [_ (nfs/check-directory-permission! repo)]
                                (fs/write-file! repo (config/get-repo-dir repo) path content
-                                               {:old-content original-content
-                                                :last-modified-at (db/get-file-last-modified-at repo path)}))
+                                               {:old-content original-content}))
                              (p/catch (fn [error]
                                         (log/error :write-file/failed {:path path
                                                                        :content content