From 606c3c05e7c8f105bc274b9fda082a021c4d2264 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 24 Jan 2022 10:58:34 +0800 Subject: [PATCH] Sync bookmarks Signed-off-by: Andrea Maria Piana --- src/status_im/browser/core.cljs | 42 +++++++++++++------ src/status_im/ethereum/json_rpc.cljs | 3 +- src/status_im/subs.cljs | 6 +++ src/status_im/transport/message/core.cljs | 9 ++++ .../ui/screens/browser/empty_tab/views.cljs | 2 +- .../ui/screens/browser/options/views.cljs | 2 +- status-go-version.json | 6 +-- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/status_im/browser/core.cljs b/src/status_im/browser/core.cljs index 0335e72c99..52f15f3427 100644 --- a/src/status_im/browser/core.cljs +++ b/src/status_im/browser/core.cljs @@ -107,28 +107,37 @@ {:keys [url] :as bookmark}] {:db (assoc-in db [:bookmarks/bookmarks url] bookmark) ::json-rpc/call [{:method "browsers_storeBookmark" + :params [bookmark] + :on-success #(re-frame/dispatch [:browser/sync-bookmark %1])}]}) + +(fx/defn sync-bookmark + {:events [:browser/sync-bookmark]} + [_ bookmark] + {::json-rpc/call [{:method "wakuext_syncBookmark" :params [bookmark] :on-success #()}]}) (fx/defn update-bookmark {:events [:browser/update-bookmark]} - [{:keys [db]} + [{:keys [db] :as cofx} {:keys [url] :as bookmark}] - {:db (update-in db - [:bookmarks/bookmarks url] - merge bookmark) - ::json-rpc/call [{:method "browsers_updateBookmark" - :params [url bookmark] - :on-success #()}]}) + (let [old-bookmark (get-in db [:bookmarks/bookmarks url]) + new-bookmark (merge old-bookmark bookmark)] + (fx/merge cofx {:db (assoc-in db [:bookmarks/bookmarks url] new-bookmark) + ::json-rpc/call [{:method "browsers_updateBookmark" + :params [url bookmark] + :on-success #(re-frame/dispatch [:browser/sync-bookmark new-bookmark])}]}))) (fx/defn delete-bookmark {:events [:browser/delete-bookmark]} - [{:keys [db]} + [{:keys [db] :as cofx} url] - {:db (update db :bookmarks/bookmarks dissoc url) - ::json-rpc/call [{:method "browsers_deleteBookmark" - :params [url] - :on-success #()}]}) + (let [old-bookmark (get-in db [:bookmarks/bookmarks url]) + removed-bookmark (merge old-bookmark {:removed true})] + (fx/merge cofx {:db (update db :bookmarks/bookmarks dissoc url) + ::json-rpc/call [{:method "browsers_removeBookmark" + :params [url] + :on-success #(re-frame/dispatch [:browser/sync-bookmark removed-bookmark])}]}))) (defn can-go-back? [{:keys [history-index]}] (pos? history-index)) @@ -558,3 +567,12 @@ {:events [:browser/loading-started]} [cofx] (update-browser-options cofx {:error? false :loading? true})) + +(fx/defn handle-bookmarks + [{:keys [db]} bookmarks] + (let [changed-bookmarks (reduce (fn [acc {:keys [url] :as bookmark}] + (assoc acc url bookmark)) + {} + bookmarks) + stored-bookmarks (get-in db [:bookmarks/bookmarks])] + {:db (assoc-in db [:bookmarks/bookmarks] (merge stored-bookmarks changed-bookmarks))})) \ No newline at end of file diff --git a/src/status_im/ethereum/json_rpc.cljs b/src/status_im/ethereum/json_rpc.cljs index 608f5bb822..ed4c10dc0e 100644 --- a/src/status_im/ethereum/json_rpc.cljs +++ b/src/status_im/ethereum/json_rpc.cljs @@ -55,6 +55,7 @@ "wakuext_startMessenger" {} "wakuext_sendPairInstallation" {} "wakuext_syncDevices" {} + "wakuext_syncBookmark" {} "wakuext_requestMessages" {} "wakuext_sendDirectMessage" {} "wakuext_sendPublicMessage" {} @@ -210,7 +211,7 @@ "browsers_getBookmarks" {} "browsers_storeBookmark" {} "browsers_updateBookmark" {} - "browsers_deleteBookmark" {} + "browsers_removeBookmark" {} "mailservers_getMailserverRequestGaps" {} "mailservers_addMailserverRequestGaps" {} "mailservers_deleteMailserverRequestGaps" {} diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 31e609427b..abcba7c3b7 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -2941,3 +2941,9 @@ (>= (count new-password) 6) (>= (count current-password) 6) (= new-password confirm-new-password))}))) + +(re-frame/reg-sub + :bookmarks/active + :<- [:bookmarks] + (fn [bookmarks] + (into {} (remove #(:removed (second %)) bookmarks)))) \ No newline at end of file diff --git a/src/status_im/transport/message/core.cljs b/src/status_im/transport/message/core.cljs index 08ebc473bb..d72f5a485b 100644 --- a/src/status_im/transport/message/core.cljs +++ b/src/status_im/transport/message/core.cljs @@ -20,6 +20,7 @@ [status-im.multiaccounts.model :as multiaccounts.model] [status-im.notifications-center.core :as notifications-center] [status-im.visibility-status-updates.core :as models.visibility-status-updates] + [status-im.browser.core :as browser] [clojure.string :as string])) (fx/defn process-next @@ -45,6 +46,7 @@ ^js removed-messages (.-removedMessages response-js) ^js visibility-status-updates (.-statusUpdates response-js) ^js current-visibility-status (.-currentStatus response-js) + ^js bookmarks (.-bookmarks response-js) ^js cleared-histories (.-clearedHistories response-js) sync-handler (when-not process-async process-response)] (cond @@ -91,6 +93,13 @@ (process-next response-js sync-handler) (models.communities/handle-communities communities-clj))) + (seq bookmarks) + (let [bookmarks-clj (types/js->clj bookmarks)] + (js-delete response-js "bookmarks") + (fx/merge cofx + (process-next response-js sync-handler) + (browser/handle-bookmarks cofx bookmarks-clj))) + (seq pin-messages) (let [pin-messages (types/js->clj pin-messages)] (js-delete response-js "pinMessages") diff --git a/src/status_im/ui/screens/browser/empty_tab/views.cljs b/src/status_im/ui/screens/browser/empty_tab/views.cljs index deafe86f7a..0b457eb6a4 100644 --- a/src/status_im/ui/screens/browser/empty_tab/views.cljs +++ b/src/status_im/ui/screens/browser/empty_tab/views.cljs @@ -108,7 +108,7 @@ [icons/icon :main-icons/dropdown {:color colors/white-transparent-persist}]]]])) (views/defview empty-tab [] - (views/letsubs [bookmarks [:bookmarks] + (views/letsubs [bookmarks [:bookmarks/active] dapps-account [:dapps-account] url-text (atom nil)] (let [bookmarks (vals bookmarks)] diff --git a/src/status_im/ui/screens/browser/options/views.cljs b/src/status_im/ui/screens/browser/options/views.cljs index f09442e979..94162335ce 100644 --- a/src/status_im/ui/screens/browser/options/views.cljs +++ b/src/status_im/ui/screens/browser/options/views.cljs @@ -39,7 +39,7 @@ (defn browser-options [url account empty-tab name] (fn [] (let [topic (http/topic-from-url url) - bookmarks @(re-frame/subscribe [:bookmarks]) + bookmarks @(re-frame/subscribe [:bookmarks/active]) permissions @(re-frame/subscribe [:dapps/permissions]) fav? (get bookmarks url) connected? (some #{constants/dapp-permission-web3} (get-in permissions [(http/url-host url) :permissions]))] diff --git a/status-go-version.json b/status-go-version.json index f3e7d99fd7..e280a3694f 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.94.3", - "commit-sha1": "07b9c3c7de5e155ef257e729161c101ccc3ead27", - "src-sha256": "0njp130h3d5k5p694as4y4s012q0s5jwx3p5s98aqj4kh06fyy04" + "version": "v0.94.4", + "commit-sha1": "4cc53630d5cbe10ce28103154bd4cfe926176ccc", + "src-sha256": "082wrqwjk27cijfd4vl7ma5qpd6vg01kh3k80va9l9693vn3ljdh" }