[#7262] Remove shortcut creation when following universal links inside status

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2019-02-25 13:34:07 +03:00
parent 520f6ad354
commit c491654eec
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
4 changed files with 39 additions and 25 deletions

View File

@ -212,11 +212,6 @@
(utils.universal-links/handle-url cofx link) (utils.universal-links/handle-url cofx link)
{:browser/show-browser-selection link})) {:browser/show-browser-selection link}))
(fx/defn handle-universal-link
[cofx link]
(when (utils.universal-links/universal-link? link)
(utils.universal-links/handle-url cofx link)))
(fx/defn update-browser-on-nav-change (fx/defn update-browser-on-nav-change
[cofx url error?] [cofx url error?]
(let [browser (get-current-browser (:db cofx)) (let [browser (get-current-browser (:db cofx))
@ -228,7 +223,6 @@
(fx/merge cofx (fx/merge cofx
(update-browser-history browser resolved-url) (update-browser-history browser resolved-url)
(handle-pdf url) (handle-pdf url)
(handle-universal-link url)
(resolve-url {:error? error? :resolved-url (when resolved-ens url)})))))) (resolve-url {:error? error? :resolved-url (when resolved-ens url)}))))))
(fx/defn update-browser-name (fx/defn update-browser-name
@ -239,24 +233,29 @@
(fx/defn navigation-state-changed (fx/defn navigation-state-changed
[cofx event error?] [cofx event error?]
(let [{:strs [url loading title]} (js->clj event)] (let [{:strs [url loading title]} (js->clj event)
(fx/merge cofx deep-link? (utils.universal-links/deep-link? url)]
(update-browser-option :loading? loading) (if (utils.universal-links/universal-link? url)
(update-browser-name title) (when-not (and deep-link? platform/ios?) ;; ios webview handles this
(update-browser-on-nav-change url error?)))) (utils.universal-links/handle-url cofx url))
(fx/merge cofx
(update-browser-option :loading? loading)
(update-browser-name title)
(update-browser-on-nav-change url error?)))))
(fx/defn open-url-in-current-browser (fx/defn open-url-in-current-browser
"Opens a url in the current browser, which mean no new entry is added to the home page "Opens a url in the current browser, which mean no new entry is added to the home page
and history of the current browser is updated so that the user can navigate back to the and history of the current browser is updated so that the user can navigate back to the
origin url" origin url"
;; TODO(yenda) is that desirable ?
[cofx url] [cofx url]
(let [browser (get-current-browser (:db cofx)) (let [browser (get-current-browser (:db cofx))
normalized-url (http/normalize-and-decode-url url)] normalized-url (http/normalize-and-decode-url url)]
(fx/merge cofx (if (utils.universal-links/universal-link? normalized-url)
(update-browser-option :url-editing? false) (utils.universal-links/handle-url cofx normalized-url)
(update-browser-history browser normalized-url) (fx/merge cofx
(resolve-url nil)))) (update-browser-option :url-editing? false)
(update-browser-history browser normalized-url)
(resolve-url nil)))))
(fx/defn open-url (fx/defn open-url
"Opens a url in the browser. If a host can be extracted from the url and "Opens a url in the browser. If a host can be extracted from the url and
@ -268,12 +267,14 @@
browser {:browser-id (or host (random/id)) browser {:browser-id (or host (random/id))
:history-index 0 :history-index 0
:history [normalized-url]}] :history [normalized-url]}]
(fx/merge cofx (if (utils.universal-links/universal-link? normalized-url)
{:db (assoc db :browser/options (utils.universal-links/handle-url cofx normalized-url)
{:browser-id (:browser-id browser)})} (fx/merge cofx
(navigate-to-browser) {:db (assoc db :browser/options
(update-browser browser) {:browser-id (:browser-id browser)})}
(resolve-url nil)))) (navigate-to-browser)
(update-browser browser)
(resolve-url nil)))))
(fx/defn open-existing-browser (fx/defn open-existing-browser
"Opens an existing browser with it's history" "Opens an existing browser with it's history"

View File

@ -238,6 +238,8 @@
(def regx-bold #"\*[^*]+\*") (def regx-bold #"\*[^*]+\*")
(def regx-italic #"~[^~]+~") (def regx-italic #"~[^~]+~")
(def regx-backquote #"`[^`]+`") (def regx-backquote #"`[^`]+`")
(def regx-universal-link #"((^https?://get.status.im/)|(^status-im://))[\x00-\x7F]+$")
(def regx-deep-link #"(^status-im://)[\x00-\x7F]+$")
(def ^:const lines-collapse-threshold 20) (def ^:const lines-collapse-threshold 20)
(def ^:const chars-collapse-threshold 600) (def ^:const chars-collapse-threshold 600)

View File

@ -14,7 +14,8 @@
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.platform :as platform])) [status-im.utils.platform :as platform]
[status-im.constants :as constants]))
;; TODO(yenda) investigate why `handle-universal-link` event is ;; TODO(yenda) investigate why `handle-universal-link` event is
;; dispatched 7 times for the same link ;; dispatched 7 times for the same link
@ -44,7 +45,11 @@
(defn universal-link? [url] (defn universal-link? [url]
(boolean (boolean
(re-matches #"((^https?://get.status.im/)|(^status-im://))[\x00-\x7F]+$" url))) (re-matches constants/regx-universal-link url)))
(defn deep-link? [url]
(boolean
(re-matches constants/regx-deep-link url)))
(defn open! [url] (defn open! [url]
(log/info "universal-links: opening " url) (log/info "universal-links: opening " url)

View File

@ -53,6 +53,9 @@
(testing "status-im://blah" (testing "status-im://blah"
(testing "it returns true" (testing "it returns true"
(is (links/universal-link? "status-im://blah")))) (is (links/universal-link? "status-im://blah"))))
(testing "status-im://blah"
(testing "it returns true"
(is (links/deep-link? "status-im://blah"))))
(testing "http://get.status.im/blah" (testing "http://get.status.im/blah"
(testing "it returns true" (testing "it returns true"
(is (links/universal-link? "http://get.status.im/blah")))) (is (links/universal-link? "http://get.status.im/blah"))))
@ -70,7 +73,10 @@
(is (not (links/universal-link? "https://not.status.im/blah"))))) (is (not (links/universal-link? "https://not.status.im/blah")))))
(testing "https://not.status.im/blah" (testing "https://not.status.im/blah"
(testing "it returns false" (testing "it returns false"
(is (not (links/universal-link? "https://not.status.im/blah")))))) (is (not (links/universal-link? "https://not.status.im/blah")))))
(testing "http://get.status.im/blah"
(testing "it returns false"
(is (not (links/deep-link? "http://get.status.im/blah"))))))
(deftest process-stored-event (deftest process-stored-event
(testing "the url is in the database" (testing "the url is in the database"