Sync bookmarks

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
frank 2022-01-24 10:58:34 +08:00 committed by Andrea Maria Piana
parent 6cb48834ae
commit 606c3c05e7
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
7 changed files with 52 additions and 18 deletions

View File

@ -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))}))

View File

@ -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" {}

View File

@ -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))))

View File

@ -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")

View File

@ -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)]

View File

@ -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]))]

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"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"
}