From 29030db2b644a8221d0eeae8a2180077e36ae2ff Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Mon, 23 Oct 2017 11:40:36 +0300 Subject: [PATCH] browse from message bug --- src/status_im/chat/events.cljs | 11 +++++++++++ src/status_im/chat/views/message/message.cljs | 4 ++-- src/status_im/components/list_selection.cljs | 9 +++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 3b3bcfe48f..6e1a2c3d07 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -12,6 +12,7 @@ [status-im.data-store.chats :as chats-store] [status-im.protocol.core :as protocol] [status-im.constants :as const] + [status-im.components.list-selection :as list-selection] status-im.chat.events.input status-im.chat.events.commands status-im.chat.events.animation @@ -78,6 +79,11 @@ (fn [params] (protocol/send-seen! params))) +(re-frame/reg-fx + :browse + (fn [[command link]] + (list-selection/browse command link))) + ;;;; Helper fns (defn init-console-chat @@ -251,3 +257,8 @@ {:db (assoc-in [:chats current-chat-id :messages] (get-stored-messages current-chat-id)) ;; TODO(janherich): make this dispatch into fn call once commands loading is refactored :dispatch [:load-commands! current-chat-id]})))) + +(handlers/register-handler-fx + :browse-link-from-message + (fn [{{:keys [global-commands]} :db} [_ link]] + {:browse [(:browse global-commands) link]})) \ No newline at end of file diff --git a/src/status_im/chat/views/message/message.cljs b/src/status_im/chat/views/message/message.cljs index 43871a950b..e3d883ecee 100644 --- a/src/status_im/chat/views/message/message.cljs +++ b/src/status_im/chat/views/message/message.cljs @@ -15,7 +15,7 @@ get-dimensions dismiss-keyboard!]] [status-im.components.animation :as anim] - [status-im.components.list-selection :refer [share browse share-or-open-map]] + [status-im.components.list-selection :refer [share share-or-open-map]] [status-im.chat.constants :as chat-consts] [status-im.chat.models.commands :as commands] [status-im.chat.styles.message.message :as st] @@ -200,7 +200,7 @@ (if simple-text? [autolink {:style (st/text-message message) :text (apply str parsed-text) - :onPress #(browse %)}] + :onPress #(dispatch [:browse-link-from-message %])}] [text {:style (st/text-message message)} parsed-text]))]) (defmulti message-content (fn [_ message _] (message :content-type))) diff --git a/src/status_im/components/list_selection.cljs b/src/status_im/components/list_selection.cljs index a4d4ae69a6..b01cb63801 100644 --- a/src/status_im/components/list_selection.cljs +++ b/src/status_im/components/list_selection.cljs @@ -28,7 +28,7 @@ :default)) :cancel-text (label :t/sharing-cancel)}))) -(defn browse [link] +(defn browse [command link] (let [list-selection-fn (:list-selection-fn platform-specific)] (list-selection-fn {:title (label :t/browsing-title) :options [{:text (label :t/browsing-browse)} @@ -37,9 +37,10 @@ (case index 0 (do (dispatch [:select-chat-input-command - {:bot "browse" - :prefill [link]}]) - (js/setTimeout #(dispatch [:send-current-message]) 500)) + (assoc (first command) :prefill [link]) + nil + true]) + (js/setTimeout #(dispatch [:send-current-message]) 100)) 1 (.openURL linking link) :default)) :cancel-text (label :t/browsing-cancel)})))