[Fixes #4944] Enable universal/deep links

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-07-03 16:59:19 +02:00
parent c0e5d24791
commit f36d5d64cc
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
9 changed files with 50 additions and 22 deletions

View File

@ -20,4 +20,3 @@ GROUP_CHATS_ENABLED=0
USE_SYM_KEY=0
MAINNET_WARNING_ENABLED=1
SPAM_BUTTON_DETECTION_ENABLED=1
UNIVERSAL_LINKS_ENABLED=0

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Spam moderation
- Collectibles support (CryptoKitties, CryptoStrikers and Etheremon)
- Added more dapps
- Universal and deep links for public chats, browsing dapps, viewing profiles
### Fixed
- Fixed mailservers connectivity issue

View File

@ -386,16 +386,16 @@
(navigate-to-chat random-id {})
(transport.message/send (group-chat/GroupAdminUpdate. chat-name selected-contacts) random-id)))))
(defn show-profile [identity {:keys [db] :as cofx}]
(handlers-macro/merge-fx cofx
{:db (assoc db :contacts/identity identity)}
(navigation/navigate-forget :profile)))
(defn show-profile [identity keep-navigation? {:keys [db] :as cofx}]
(cond->> {:db (assoc db :contacts/identity identity)}
keep-navigation? (navigation/navigate-to-cofx :profile nil)
:else (navigation/navigate-forget :profile)))
(handlers/register-handler-fx
:show-profile
[re-frame/trim-v]
(fn [cofx [identity]]
(show-profile identity cofx)))
(fn [cofx [identity keep-navigation?]]
(show-profile identity keep-navigation? cofx)))
(handlers/register-handler-fx
:resend-message

View File

@ -8,7 +8,8 @@
[status-im.native-module.core :as status]
[status-im.utils.config :as config]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.utils :as utils]))
[status-im.utils.utils :as utils]
[status-im.utils.universal-links.core :as universal-links]))
;;;; FX
@ -149,10 +150,11 @@
(register-handler-fx
:change-account-handler
(fn [{{:keys [view-id] :as db} :db} [_ address]]
(fn [{{:keys [view-id] :as db} :db :as cofx} [_ address]]
{:db (cond-> (dissoc db :accounts/login)
(= view-id :create-account)
(assoc-in [:accounts/create :step] :enter-name))
:dispatch [:initialize-account address
(when (not= view-id :create-account)
[[:navigate-to-clean :home]])]}))
[[:navigate-to-clean :home]
(universal-links/stored-url-event cofx)])]}))

View File

@ -13,7 +13,6 @@
status-im.ui.screens.group.chat-settings.events
status-im.ui.screens.group.events
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.universal-links.core :as universal-links]
status-im.utils.universal-links.events
[status-im.chat.commands.core :as commands]
status-im.ui.screens.add-new.new-chat.navigation
@ -375,8 +374,7 @@
[:update-transactions]
[:get-fcm-token]
[:update-sign-in-time]
[:show-mainnet-is-default-alert]
(universal-links/stored-url-event cofx)]
[:show-mainnet-is-default-alert]]
(seq events-after) (into events-after))}))
(handlers/register-handler-fx

View File

@ -50,17 +50,22 @@
(dissoc db :was-modal?) ;;TODO check how it worked with this bug
(apply preload-data! db args)))
(defn navigate-to-cofx [go-to-view-id screen-params {:keys [db]}]
(let [view-id (:view-id db)
db (cond-> db
(seq screen-params)
(assoc-in [:navigation/screen-params go-to-view-id] screen-params))]
{:db (if (= view-id go-to-view-id)
db
(push-view db go-to-view-id))}))
(defn navigate-to
"Navigates to particular view"
"DEPRECATED, use navigate-to-cofx above.
Navigates to particular view"
([db go-to-view-id]
(navigate-to db go-to-view-id nil))
([{:keys [view-id] :as db} go-to-view-id screen-params]
(let [db (cond-> db
(seq screen-params)
(assoc-in [:navigation/screen-params go-to-view-id] screen-params))]
(if (= view-id go-to-view-id)
db
(push-view db go-to-view-id)))))
(:db (navigate-to-cofx go-to-view-id screen-params {:db db}))))
(def unload-data-interceptor
(re-frame/->interceptor

View File

@ -19,7 +19,7 @@
(defn universal-link? [url]
(boolean
(re-matches #"((^https?://get.status.im/)|(^status-im://)).*$" url)))
(re-matches #"((^https?://get.status.im/)|(^status-im://))[\x00-\x7F]+$" url)))
(defn open! [url]
(log/info "universal-links: opening " url)
@ -39,7 +39,7 @@
(defn handle-view-profile [profile-id cofx]
(log/info "universal-links: handling view profile" profile-id)
(chat.events/show-profile profile-id cofx))
(chat.events/show-profile profile-id true cofx))
(defn handle-not-found [full-url]
(log/info "universal-links: no handler for " full-url))

View File

@ -83,3 +83,23 @@
(is (= #{"4" "5" "6"}
(set (get-in (chat-events/mark-messages-seen "1-1" {:db test-db})
[:shh/post 0 :message :payload :message-ids]))))))
(deftest show-profile-test
(testing "default behaviour"
(testing "it navigates to profile but forgets the navigation"
(let [{:keys [db]} (chat-events/show-profile
"a"
false
{:db {:navigation-stack '(:home)}})]
(is (= "a" (:contacts/identity db)))
(is (= '(:home) (:navigation-stack db)))
(is (= :profile (:view-id db))))))
(testing "keep-navigation? on"
(testing "it navigates to profile and keeps the navigation"
(let [{:keys [db]} (chat-events/show-profile
"a"
true
{:db {:navigation-stack '(:home)}})]
(is (= "a" (:contacts/identity db)))
(is (= '(:profile :home) (:navigation-stack db)))
(is (= :profile (:view-id db)))))))

View File

@ -62,6 +62,9 @@
(testing "https://get.status.im/blah"
(testing "it returns true"
(is (links/universal-link? "https://get.status.im/blah"))))
(testing "unicode characters"
(testing "it returns false"
(is (not (links/universal-link? "https://get.status.im/browse/www.аррӏе.com")))))
(testing "not-status-im://blah"
(testing "it returns false"
(is (not (links/universal-link? "https://not.status.im/blah")))))