[#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)
{: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
[cofx url error?]
(let [browser (get-current-browser (:db cofx))
@ -228,7 +223,6 @@
(fx/merge cofx
(update-browser-history browser resolved-url)
(handle-pdf url)
(handle-universal-link url)
(resolve-url {:error? error? :resolved-url (when resolved-ens url)}))))))
(fx/defn update-browser-name
@ -239,24 +233,29 @@
(fx/defn navigation-state-changed
[cofx event error?]
(let [{:strs [url loading title]} (js->clj event)]
(fx/merge cofx
(update-browser-option :loading? loading)
(update-browser-name title)
(update-browser-on-nav-change url error?))))
(let [{:strs [url loading title]} (js->clj event)
deep-link? (utils.universal-links/deep-link? url)]
(if (utils.universal-links/universal-link? url)
(when-not (and deep-link? platform/ios?) ;; ios webview handles this
(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
"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
origin url"
;; TODO(yenda) is that desirable ?
[cofx url]
(let [browser (get-current-browser (:db cofx))
normalized-url (http/normalize-and-decode-url url)]
(fx/merge cofx
(update-browser-option :url-editing? false)
(update-browser-history browser normalized-url)
(resolve-url nil))))
(if (utils.universal-links/universal-link? normalized-url)
(utils.universal-links/handle-url cofx normalized-url)
(fx/merge cofx
(update-browser-option :url-editing? false)
(update-browser-history browser normalized-url)
(resolve-url nil)))))
(fx/defn open-url
"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))
:history-index 0
:history [normalized-url]}]
(fx/merge cofx
{:db (assoc db :browser/options
{:browser-id (:browser-id browser)})}
(navigate-to-browser)
(update-browser browser)
(resolve-url nil))))
(if (utils.universal-links/universal-link? normalized-url)
(utils.universal-links/handle-url cofx normalized-url)
(fx/merge cofx
{:db (assoc db :browser/options
{:browser-id (:browser-id browser)})}
(navigate-to-browser)
(update-browser browser)
(resolve-url nil)))))
(fx/defn open-existing-browser
"Opens an existing browser with it's history"

View File

@ -238,6 +238,8 @@
(def regx-bold #"\*[^*]+\*")
(def regx-italic #"~[^~]+~")
(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 chars-collapse-threshold 600)

View File

@ -14,7 +14,8 @@
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[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
;; dispatched 7 times for the same link
@ -44,7 +45,11 @@
(defn universal-link? [url]
(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]
(log/info "universal-links: opening " url)

View File

@ -53,6 +53,9 @@
(testing "status-im://blah"
(testing "it returns true"
(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 "it returns true"
(is (links/universal-link? "http://get.status.im/blah"))))
@ -70,7 +73,10 @@
(is (not (links/universal-link? "https://not.status.im/blah")))))
(testing "https://not.status.im/blah"
(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
(testing "the url is in the database"